public class ShowEllipse extends Application
class MyEllipse extends Pane
1:
2: import javafx.application.Application;
3: import javafx.scene.Scene;
4: import javafx.scene.layout.Pane;
5: import javafx.scene.paint.Color;
6: import javafx.stage.Stage;
7: import javafx.scene.shape.Ellipse;
8:
9: public class ShowEllipse extends Application {
10: @Override // Override the start method in the Application class
11: public void start(Stage primaryStage) {
12: // Create a scene and place it in the stage
13: Scene scene = new Scene(new MyEllipse(), 300, 200);
14: primaryStage.setTitle("ShowEllipse"); // Set the stage title
15: primaryStage.setScene(scene); // Place the scene in the stage
16: primaryStage.show(); // Display the stage
17: }
18:
19: /**
20: * The main method is only needed for the IDE with limited
21: * JavaFX support. Not needed for running from the command line.
22: */
23: public static void main(String[] args) {
24: launch(args);
25: }
26: }
27:
28: class MyEllipse extends Pane {
29: private void paint() {
30: getChildren().clear();
31: for (int i = 0; i < 16; i++) {
32: // Create an ellipse and add it to pane
33: Ellipse e1 = new Ellipse(getWidth() / 2, getHeight() / 2,
34: getWidth() / 2 - 50, getHeight() / 2 - 50);
35: e1.setStroke(Color.color(Math.random(), Math.random(),
36: Math.random()));
37: e1.setFill(Color.WHITE);
38: e1.setRotate(i * 180 / 16);
39: getChildren().add(e1);
40: }
41: }
42:
43: @Override
44: public void setWidth(double width) {
45: super.setWidth(width);
46: paint();
47: }
48:
49: @Override
50: public void setHeight(double height) {
51: super.setHeight(height);
52: paint();
53: }
54: }