import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.text.Font;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.scene.layout.GridPane;
import javafx.geometry.Insets;
import javafx.stage.Stage;
public class HelloApplication extends Application{
@Override
public void start(Stage primaryStage){
GridPane pane=new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11,12,13,14));
pane.setHgap(5);
pane.setVgap(5);
Label label1=new Label("Welcome");
label1.setFont(Font.font(20));
pane.add(label1,0,0);
pane.add(new Label("User Name:"),0,1);
pane.add(new TextField(),1,1);
pane.add(new Label("Password:"),0,2);
final PasswordField pb = new PasswordField();
pane.add(pb,1,2);
Button bt=new Button("Sign in");
pane.add(bt,1,3);
GridPane.setHalignment(bt,HPos.RIGHT);
if(pb.getText().equals("123")) {
bt.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setContentText("登录成功");
alert.setTitle("登录成功");
alert.setHeaderText("");
alert.show();
}
});
}
else {
bt.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("登录失败");
alert.setTitle("登录失败");
alert.setHeaderText("");
alert.show();
}
});
}
Scene scene=new Scene(pane,400,250);
primaryStage.setTitle("JavaFx Welcome");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String args){
Application.launch(args);
}
}