Guest User

Untitled

a guest
Oct 5th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. package gui;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.EventHandler;
  5. import javafx.geometry.Insets;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.*;
  9. import javafx.scene.input.MouseEvent;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.scene.layout.HBox;
  12. import javafx.scene.paint.Color;
  13. import javafx.scene.text.Font;
  14. import javafx.scene.text.FontPosture;
  15. import javafx.scene.text.Text;
  16. import javafx.stage.Stage;
  17.  
  18. public class Login extends Application {
  19. double d = 0.0;
  20.  
  21. @Override
  22. public void start(Stage primaryStage) throws Exception {
  23.  
  24. GridPane grid = new GridPane();
  25. grid.setAlignment(Pos.CENTER);
  26. grid.setHgap(10);
  27. grid.setVgap(10);
  28. grid.setPadding(new Insets(20, 20, 20, 20));
  29. grid.setGridLinesVisible(false);
  30.  
  31. Scene scene = new Scene(grid, 450, 275);
  32. primaryStage.setTitle("窗口标题");
  33. primaryStage.setScene(scene);
  34. scene.getStylesheets().add(Login.class.getResource("login.css").toExternalForm());
  35.  
  36. // 控件 ******************************
  37. Text sceneTitle = new Text("Welcome");
  38. sceneTitle.setId("sceneTitle");
  39. sceneTitle.setFont(Font.font("Consolas", FontPosture.ITALIC, 22));
  40. grid.add(sceneTitle, 0, 0, 2, 1);
  41.  
  42. Label userName = new Label("Username: ");
  43. grid.add(userName, 0, 1);
  44. TextField userTextField = new TextField();
  45. userTextField.setText("root");
  46. grid.add(userTextField, 1, 1);
  47.  
  48. Label pw = new Label("Password:");
  49. grid.add(pw, 0, 2);
  50. PasswordField pwBox = new PasswordField();
  51. grid.add(pwBox, 1, 2);
  52.  
  53. Text msg = new Text();
  54. grid.add(msg, 1, 4);
  55.  
  56. Button btn = new Button("Login");
  57. HBox hbBtn = new HBox(10);
  58. hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  59. hbBtn.getChildren().add(btn);
  60. btn.setOnMouseClicked(event -> {
  61. if (userTextField.getText().equalsIgnoreCase("root")) {
  62. msg.setText("Login success.");
  63. msg.setFill(Color.GREEN);
  64. } else {
  65. msg.setText("Login failed.");
  66. msg.setFill(Color.RED);
  67. }
  68. });
  69. grid.add(hbBtn, 1, 4);
  70.  
  71. ProgressBar pb = new ProgressBar(0);
  72. ProgressIndicator pi = new ProgressIndicator(0);
  73. grid.add(pb, 1, 4);
  74. grid.add(pi, 0, 4);
  75.  
  76. /* Timer timer = new Timer();
  77. timer.schedule(new TimerTask() {
  78. @Override
  79. public void run() {
  80. if (d > 1) timer.cancel();
  81. else {
  82. d = d + 0.10;
  83. pb.setProgress(d);
  84. }
  85. }
  86. }, 0, 1000);*/
  87.  
  88. GridPane window1 = new GridPane();
  89. window1.setVgap(10);
  90. window1.setHgap(10);
  91. Text hello = new Text("Hello");
  92. hello.setFont(Font.font("Consolas", FontPosture.ITALIC, 20));
  93. window1.add(hello, 0, 1);
  94. Scene window = new Scene(window1, 450, 275);
  95. window.getStylesheets().add(Login.class.getResource("login.css").toExternalForm());
  96.  
  97.  
  98. btn.setOnAction(event -> {
  99. primaryStage.setTitle("Window");
  100. primaryStage.setScene(window);
  101. });
  102.  
  103. primaryStage.show();
  104. }
  105.  
  106. public static void main(String[] args) {
  107. launch(args);
  108. }
  109. }
Add Comment
Please, Sign In to add comment