public class DrawFaceFX extends Application
2: import javafx.application.Application;
3: import javafx.scene.Scene;
4: import javafx.scene.canvas.Canvas;
5: import javafx.scene.canvas.GraphicsContext;
6: import javafx.scene.layout.StackPane;
7: import javafx.scene.paint.Color; // needed for green eyes
8: import javafx.scene.shape.ArcType;
9: import javafx.stage.Stage;
11: /**
12: * A program to draw a happy face.
13: *
14: * @author Mary Young (A00000000)
15: */
16: public class DrawFaceFX extends Application {
17:
18: private static final int WIDTH = 400;
19: private static final int HEIGHT = 300;
20:
21: @Override
22: public void start(Stage primaryStage) {
23: StackPane root = new StackPane();
24: root.getChildren().add(facePanel());
25:
26: Scene scene = new Scene(root, WIDTH, HEIGHT);
27:
28: primaryStage.setTitle("Happy Face");
29: primaryStage.setScene(scene);
30: primaryStage.show();
31: }
32:
33: /**
34: * Create a canvas with a happy face drawn on it.
35: *
36: * @return a canvas with a happy face drawn on it.
37: */
38: private Canvas facePanel() {
39: Canvas result = new Canvas(WIDTH, HEIGHT);
40: GraphicsContext gc = result.getGraphicsContext2D();
41:
42: // gc.setFill(Color.GREEN); // give the face green eyes
43: gc.setLineWidth(5); // make thick lines
44:
45: gc.strokeOval(100, 50, 200, 200); // face outline
46: gc.fillOval(155, 100, 10, 20); // one eye
47: gc.fillOval(230, 100, 10, 20); // other eye
48: gc.strokeArc(150, 160, 100, 50, 0, -180, ArcType.OPEN); // smile
49:
50: return result;
51: }
53: /**
54: * @param args the command line arguments -- ignored
55: */
56: public static void main(String[] args) {
57: launch(args);
58: }
59:
60: }