public class JapaneseFlagApplication extends Application
1: import javafx.application.Application;
2: import javafx.stage.Stage;
3: import javafx.scene.Scene;
4: import javafx.scene.layout.Pane;
5: import javafx.scene.canvas.Canvas;
6: import javafx.scene.canvas.GraphicsContext;
7: import javafx.scene.paint.Color;
9: /**
10: * A JavaFX Application to draw the Japanese flag.
11: *
12: * @author Mark Young (A00000000)
13: */
14: public class JapaneseFlagApplication extends Application {
16: @Override
17: public void start(Stage applicationStage) {
18: Pane pane = makePane();
20: Scene scene = new Scene(pane); // A scene containing the pane
21: applicationStage.setTitle("Japanaese Flag"); // Set window's title
22: applicationStage.setScene(scene); // Set window's scene
23: applicationStage.show(); // Display window
24: }
26: /**
27: * Create a Pane containing a picture of the Japanaese flag.
28: *
29: * @return new Pane with flag image
30: */
31: private Pane makePane() {
32: Pane pane = new Pane(); // An empty pane
33: Canvas canvas = makeFlag();
34:
35: // put it all together, give it a title, and show it
36: pane.getChildren().add(canvas); // Add canvas to pane
37: return pane;
38: }
40: // flag constants
41: private static final int WIDTH = 900;
42: private static final int HEIGHT = WIDTH * 2 / 3;
43:
44: private static final double DIAMETER = 0.6 * HEIGHT;
46: /**
47: * Create a picture of the Japanese flag.
48: *
49: * @return a new Canvas with flag image
50: */
51: private Canvas makeFlag() {
52: Canvas result = new Canvas(WIDTH, HEIGHT); // A canvas to draw on
53: double leftEdge, topEdge;
54: GraphicsContext drawing = result.getGraphicsContext2D();
55: Color red = Color.rgb(188, 0, 45);
56:
57: // calculate the edges of the blue and red stripes
58: leftEdge = (WIDTH - DIAMETER) / 2;
59: topEdge = (HEIGHT - DIAMETER) / 2;
60:
61: // draw circle -- red
62: drawing.setFill(red);
63: drawing.fillOval(leftEdge, topEdge, DIAMETER, DIAMETER);
64:
65: return result;
66: }
68: public static void main(String[] args) {
69: launch(args); // Launch application
70: }
71: }