#真的会疯,有没有人帮帮我
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class test6_2 extends Application
{
public void start(Stage primaryStage)
{
ColorOptionsPane pane=new ColorOptionsPane();
pane.setAlignment(Pos.CENTER);
Scene scene=new Scene(pane,500,500);
primaryStage.setTitle("Color Options");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
public class ColorOptionsPane extends HBox
{
private RadioButton REDButton,GREENButton,ORANGEButton,YELLOWButton,BLUEButton;
public ColorOptionsPane()
{
Rectangle rect=new Rectangle(300,300,Color.white);
StackPane rectPane=new StackPane(rect);
ToggleGroup group=new ToggleGroup();
REDButton=new RadioButton("Red");
REDButton.setSelected(true);
REDButton.setToggleGroup(group);
REDButton.setOnAction(this::processRadioButtonAction);
GREENButton=new RadioButton("Green");
GREENButton.setToggleGroup(group);
GREENButton.setOnAction(this::processRadioButtonAction);
ORANGEButton=new RadioButton("Orange");
ORANGEButton.setToggleGroup(group);
ORANGEButton.setOnAction(this::processRadioButtonAction);
YELLOWButton=new RadioButton("Yellow");
YELLOWButton.setToggleGroup(group);
YELLOWButton.setOnAction(this::processRadioButtonAction);
BLUEButton=new RadioButton("Blue");
BLUEButton.setToggleGroup(group);
BLUEButton.setOnAction(this::processRadioButtonAction);
VBox options=new VBox(REDButton,GREENButton,ORANGEButton,YELLOWButton,BLUEButton);
options.setAlignment(Pos.CENTER_LEFT);
options.setSpacing(10);
setSpacing(20);
getChildren().addAll(options,rectPane);
}
public void processRadioButtonAction(ActionEvent event)
{
if(REDButton.isSelected())
rect.setFill(Color.RED);
else if(GREENButton.isSelected())
rect.setFill(Color.GREEN);
else if(ORANGEButton.isSelected())
rect.setFill(Color.ORANGE);
else if(YELLOWButton.isSelected())
rect.setFill(Color.YELLOW);
else
rect.setFill(Color.BLUE);
}
}