1  import javafx.application.Application;
  2  import javafx.event.ActionEvent;
  3  import javafx.event.EventHandler;
  4  import javafx.geometry.Pos;
  5  import javafx.scene.Scene;
  6  import javafx.scene.control.Button;
  7  import javafx.scene.layout.StackPane;
  8  import javafx.scene.layout.HBox;
  9  import javafx.scene.layout.BorderPane;
 10  import javafx.scene.paint.Color;
 11  import javafx.scene.shape.Circle;
 12  import javafx.stage.Stage;
 13  
 14  public class ControlCircle extends Application {
 15    private CirclePane circlePane = new CirclePane();
 16  
 17    @Override // Override the start method in the Application class
 18    public void start(Stage primaryStage) {
 19      // Hold two buttons in an HBox
 20      HBox hBox = new HBox();
 21      hBox.setSpacing(10);
 22      hBox.setAlignment(Pos.CENTER);
 23      Button btEnlarge = new Button("Enlarge");
 24      Button btShrink = new Button("Shrink");
 25      hBox.getChildren().add(btEnlarge);
 26      hBox.getChildren().add(btShrink);
 27      
 28      // Create and register the handler
 29      btEnlarge.setOnAction(new EnlargeHandler());
 30  
 31      BorderPane borderPane = new BorderPane();
 32      borderPane.setCenter(circlePane);
 33      borderPane.setBottom(hBox);
 34      BorderPane.setAlignment(hBox, Pos.CENTER);
 35      
 36      // Create a scene and place it in the stage
 37      Scene scene = new Scene(borderPane, 200, 150);
 38      primaryStage.setTitle("ControlCircle"); // Set the stage title
 39      primaryStage.setScene(scene); // Place the scene in the stage
 40      primaryStage.show(); // Display the stage
 41    }
 42    
 43    class EnlargeHandler implements EventHandler<ActionEvent> {
 44      @Override // Override the handle method
 45      public void handle(ActionEvent e) {
 46        circlePane.enlarge();
 47      }
 48    }
 49    
 50    /**
 51     * The main method is only needed for the IDE with limited
 52     * JavaFX support. Not needed for running from the command line.
 53     */
 54    public static void main(String[] args) {
 55      launch(args);
 56    }
 57  }
 58  
 59  class CirclePane extends StackPane {
 60    private Circle circle = new Circle(50); 
 61    
 62    public CirclePane() {
 63      getChildren().add(circle);
 64      circle.setStroke(Color.BLACK);
 65      circle.setFill(Color.WHITE);
 66    }
 67    
 68    public void enlarge() {
 69      circle.setRadius(circle.getRadius() + 2);
 70    }
 71    
 72    public void shrink() {
 73      circle.setRadius(circle.getRadius() > 2 ? 
 74        circle.getRadius() - 2 : circle.getRadius());
 75    }
 76  }