import java.awt.Graphics;
import java.util.Scanner;
import javax.swing.JApplet;
/**
*This is a program that displays different faces
*based off of different responses.
*2/5/2010
*/
public class Program3
extends JApplet {
public static final int FACE_DIAMETER = 200;
public static final int X_FACE = 100;
public static final int Y_FACE = 50;
public static final int EYE_WIDTH = 10;
public static final int EYE_HEIGHT = 20;
public static final int X_RIGHT_EYE = 155;
public static final int Y_RIGHT_EYE = 100;
public static final int X_LEFT_EYE = 200;
public static final int Y_LEFT_EYE = Y_RIGHT_EYE;
public static final int MOUTH_WIDTH = 100;
public static final int MOUTH_HEIGHT = 200;
public static final int X_MOUTH = 150;
public static final int Y_MOUTH = 160;
public static final int MOUTH_START_ANGLE = 180;
public static final int MOUTH_EXTENT_ANGLE = 180;
public void init()
{
setSize(500, 500);
}
public void happyFace (Graphics canvas)
{
//Draw face outline
canvas.drawOval (X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
//Draw eyes
canvas.fillOval (X_RIGHT_EYE, Y_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT);
canvas.fillOval (X_LEFT_EYE, Y_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT);
//Draw mouth
canvas.drawArc (X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT,
MOUTH_START_ANGLE, MOUTH_EXTENT_ANGLE);
}
public void sadFace (Graphics canvas)
{
}
private static final long serialVersionUID = 1L;
public static final int FACE_DIAMETER2 = 200;
public static final int X_FACE2 = 100;
public static final int Y_FACE2 = 50;
public static final int EYE_WIDTH2 = 10;
public static final int EYE_HEIGHT2 = 20;
public static final int X_RIGHT_EYE2 = 155;
public static final int Y_RIGHT_EYE2 = 100;
public static final int X_LEFT_EYE2 = 200;
public static final int Y_LEFT_EYE2 = Y_RIGHT_EYE;
public static final int MOUTH_WIDTH2 = 100;
public static final int MOUTH_HEIGHT2 = 200;
public static final int X_MOUTH2 = 150;
public static final int Y_MOUTH2 = 150;
public static final int MOUTH_START_ANGLE2 = 150;
public static final int MOUTH_EXTENT_ANGLE2 = -120;
public void paint(Graphics canvas)
{
//Draw face outline:
canvas.drawOval(X_FACE2, Y_FACE2, FACE_DIAMETER2, FACE_DIAMETER2);
//Draw eyes:
canvas.fillOval(X_RIGHT_EYE2, Y_RIGHT_EYE2, EYE_WIDTH2, EYE_HEIGHT2);
canvas.fillOval(X_LEFT_EYE2, Y_LEFT_EYE2, EYE_WIDTH2, EYE_HEIGHT2);
//Draw mouth:
canvas.drawArc(X_MOUTH2, Y_MOUTH2, MOUTH_WIDTH2, MOUTH_HEIGHT2,
MOUTH_START_ANGLE2, MOUTH_EXTENT_ANGLE2);
happyFace (canvas);
sadFace (canvas);
//The following code deals with if-else and asking the user if they are happy
System.out.println("Are you happy?");
if (answer == 'y') || (answer == 'yes')
}
{
}
}