Java语言程序设计第十版第十六章16.3课后操作题答案

16.3

public class Exercise16_3 extends Application{
	public void start(Stage args){
		Rectangle rectangle = new Rectangle(200,30,100,220); 
		rectangle.setStroke(Color.BLACK);
		rectangle.setFill(Color.TRANSPARENT);
		
		VBox vboxforcircles = new VBox(10); 
		Circle circle1 = new Circle(30);
		circle1.setStroke(Color.BLACK);
		circle1.setFill(Color.TRANSPARENT);
		Circle circle2 = new Circle(30);
		circle2.setStroke(Color.BLACK);
		circle2.setFill(Color.TRANSPARENT);
		Circle circle3 = new Circle(30);
		circle3.setStroke(Color.BLACK);
		circle3.setFill(Color.TRANSPARENT);
		vboxforcircles.getChildren().addAll(circle1, circle2, circle3); 
		vboxforcircles.setLayoutX(220);
		vboxforcircles.setLayoutY(40);
		
		HBox hboxforbuttons = new HBox(20);
		RadioButton btRed = new RadioButton("Red");
		RadioButton btYellow = new RadioButton("Yellow");
		RadioButton btGreen = new RadioButton("Green");
		hboxforbuttons.getChildren().addAll(btRed, btYellow, btGreen);
		hboxforbuttons.setAlignment(Pos.CENTER);
		
		ToggleGroup group = new ToggleGroup();
		btRed.setToggleGroup(group);
		btYellow.setToggleGroup(group);
		btGreen.setToggleGroup(group);
		
		Pane pane = new Pane();
		pane.getChildren().addAll(rectangle, vboxforcircles);
		
		BorderPane bpane = new BorderPane();   
		bpane.setCenter(pane);
		bpane.setBottom(hboxforbuttons);
		
		btRed.setOnAction(new EventHandler() { 
			public void handle(ActionEvent arg0) { 
				circle1.setFill(Color.RED);
				circle2.setFill(Color.TRANSPARENT);
				circle3.setFill(Color.TRANSPARENT);
			}
		});
		
		btYellow.setOnAction(new EventHandler() { 
			public void handle(ActionEvent arg0) {  
				circle2.setFill(Color.YELLOW);
				circle1.setFill(Color.TRANSPARENT);
				circle3.setFill(Color.TRANSPARENT);
			}
		});
		
		btGreen.setOnAction(new EventHandler() { 
			public void handle(ActionEvent arg0) { 
				circle3.setFill(Color.GREEN);
				circle1.setFill(Color.TRANSPARENT);
				circle2.setFill(Color.TRANSPARENT);
			}
		});
		
		Scene scene = new Scene(bpane, 500, 300);
		args.setTitle("Exercise16_3");
		args.setScene(scene);
		args.show();
	}
	public static void main(String[] args){
		Application.launch(args);
	}

}

你可能感兴趣的:(Java语言程序设计第十版第十六章16.3课后操作题答案)