package fx;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Exercise16_02 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
StackPane stackPane = new StackPane();
RadioButton circle = new RadioButton("Circle");
RadioButton rectangle = new RadioButton("Rectangle");
RadioButton ellipse = new RadioButton("Ellipse");
CheckBox fill = new CheckBox("Fill");
ToggleGroup toggleGroup = new ToggleGroup();
circle.setToggleGroup(toggleGroup);
rectangle.setToggleGroup(toggleGroup);
ellipse.setToggleGroup(toggleGroup);
HBox bottomHBox = new HBox(10, circle, rectangle, ellipse, fill);
bottomHBox.setAlignment(Pos.CENTER);
circle.setOnAction(event -> {
if (circle.isSelected()) {
Circle c = new Circle(50);
if (fill.isSelected())
c.setStyle("-fx-fill: black; -fx-stroke: black;");
else
c.setStyle("-fx-fill: null; -fx-stroke: black;");
stackPane.getChildren().clear();
stackPane.getChildren().add(c);
}
});
rectangle.setOnAction(event -> {
if (rectangle.isSelected()) {
Rectangle r = new Rectangle(100, 50);
if (fill.isSelected())
r.setStyle("-fx-fill: black; -fx-stroke: black;");
else
r.setStyle("-fx-fill: null; -fx-stroke: black;");
stackPane.getChildren().clear();
stackPane.getChildren().add(r);
}
});
ellipse.setOnAction(event -> {
if (ellipse.isSelected()) {
Ellipse e = new Ellipse(50, 25);
if (fill.isSelected())
e.setStyle("-fx-fill: black; -fx-stroke: black;");
else
e.setStyle("-fx-fill: null; -fx-stroke: black;");
stackPane.getChildren().clear();
stackPane.getChildren().add(e);
}
});
fill.setOnAction(event -> {
if (fill.isSelected())
stackPane.getChildren().get(0).setStyle("-fx-fill: black; -fx-stroke: black;");
else
stackPane.getChildren().get(0).setStyle("-fx-fill: null; -fx-stroke: black;");
});
BorderPane pane = new BorderPane(stackPane);
pane.setBottom(bottomHBox);
pane.getCenter().setStyle("-fx-border-color: black;");
Scene scene = new Scene(pane, 350, 200);
primaryStage.setScene(scene);
primaryStage.setTitle("Exercise16_02");
primaryStage.show();
}
}