Java Reference
In-Depth Information
The arguments
MOUTH_WIDTH
and
MOUTH_HEIGHT
determine the size of an invisible
rectangle. The arguments
X_MOUTH
and
Y_MOUTH
determine the location of the
rectangle. The upper-left corner of the rectangle is located at the point
(X_MOUTH,
Y_MOUTH).
Inside this invisible rectangle, envision an invisible oval that just fits inside
the invisible rectangle. The last two arguments specify the portion of this invisible oval
that is made visible.
Display 18.14 illustrates how these last two arguments specify an arc of the invisible
oval to be made visible. The next-to-last argument specifies a start angle in degrees.
The last argument specifies how many degrees of the oval's arc will be made visible. If
the last argument is 360 (degrees), then the full oval is made visible.
Display 18.13
Drawing a Happy Face (
part 1 of 2)
1
import
javax.swing.JFrame;
2
import
java.awt.Graphics;
3
import
java.awt.Color;
4
public class
HappyFace extends JFrame
5 {
6
public static final int
WINDOW_WIDTH = 400;
7
public static final int
WINDOW_HEIGHT = 400;
8
public static final int
FACE_DIAMETER = 200;
9
public static final int
X_FACE = 100;
10
public static final int
Y_FACE = 100;
11
public static final int
EYE_WIDTH = 20;
12
public static final int
EYE_HEIGHT = 10;
13
public static final int
X_RIGHT_EYE = X_FACE + 55;
14
public static final int
Y_RIGHT_EYE = Y_FACE + 60;
15
public static final int
X_LEFT_EYE = X_FACE + 130;
16
public static final int
Y_LEFT_EYE = Y_FACE + 60;
17
public static final int
MOUTH_WIDTH = 100;
18
public static final int
MOUTH_HEIGHT = 50;
19
public static final int
X_MOUTH = X_FACE + 50;
20
public static final int
Y_MOUTH = Y_FACE + 100;
21
public static final int
MOUTH_START_ANGLE = 180;
22
public static final int
MOUTH_ARC_SWEEP = 180;
23
public static void
main(String[] args)
24 {
25 HappyFace drawing =
new
HappyFace();
26 drawing.setVisible(
true
);
27 }