请使用junit
帮助测试此代码@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text scenetitle = new Text("Welcome");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, 0, 0, 2, 1);
Label userName = new Label("User Name:");
grid.add(userName, 0, 1);
TextField userTextField = new TextField();
grid.add(userTextField, 1, 1);
Label pw = new Label("Password:");
grid.add(pw, 0, 2);
PasswordField pwBox = new PasswordField();
grid.add(pwBox, 1, 2);
Label status = new Label();
status.setId( "status-label" );
Button btn = new Button("Sign in");
btn.setId("btn");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);
grid.add(status, 1, 8);
final Text actiontarget = new Text();
grid.add(actiontarget, 1, 6);
// ImageView imageView = new ImageView(new Image(getClass().getResourceAsStream("person.png"), 0, 65, true, true));
//grid.add(imageView, 0, 0,2,2);
//btn.setOnAction( ( e ) -> status.setText( computeStatus() ) );
//private String computeStatus() {
// return "Name: " + userTextField.getText() + ", Password: " + pwBox.getText();
//}
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
actiontarget.setFill(Color.CORNFLOWERBLUE);
actiontarget.setText("Name: " + userTextField.getText() + ", Password: " + pwBox.getText());
}
});
Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}