Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.Insets;
  3. import javafx.geometry.Pos;
  4. import javafx.scene.Scene;
  5. import javafx.scene.control.Button;
  6. import javafx.scene.control.Label;
  7. import javafx.scene.control.PasswordField;
  8. import javafx.scene.control.TextField;
  9. import javafx.scene.layout.GridPane;
  10. import javafx.scene.text.Font;
  11. import javafx.scene.text.FontWeight;
  12. import javafx.stage.Stage;
  13.  
  14. public class Main extends Application {
  15.  
  16. Stage window;
  17.  
  18. public static void main(String[] args) {
  19. launch(args);
  20. }
  21.  
  22. @Override
  23. public void start(Stage primaryStage) throws Exception {
  24. window = primaryStage;
  25. window.setTitle("thenewboston - JavaFX");
  26.  
  27. //GridPane with 10px padding around edge
  28. GridPane grid = new GridPane();
  29. grid.setPadding(new Insets(10));
  30. grid.setVgap(10);
  31. grid.setHgap(10);
  32. grid.setAlignment(Pos.CENTER);
  33. //Name Label - constrains use (child, column, row)
  34. Label nameLabel = new Label("Username:");
  35. GridPane.setConstraints(nameLabel, 0, 0);
  36. nameLabel.setFont(Font.font("Tahoma", FontWeight.LIGHT, 25));
  37. //Name Input
  38. TextField nameInput = new TextField("Username");
  39. GridPane.setConstraints(nameInput, 1, 0);
  40.  
  41. //Password Label
  42. Label passLabel = new Label("Password:");
  43. GridPane.setConstraints(passLabel, 0, 1);
  44.  
  45. //Password Input
  46. PasswordField passInput = new PasswordField();
  47. passInput.setPromptText("password");
  48. GridPane.setConstraints(passInput, 1, 1);
  49.  
  50. //Login
  51. Button loginButton = new Button("Log In");
  52. GridPane.setConstraints(loginButton, 1, 2);
  53.  
  54. //Add everything to grid
  55. grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);
  56. loginButton.setOnAction(e -> {
  57. System.out.println(nameInput.getText());
  58. });
  59. Scene scene = new Scene(grid, 800, 600);
  60. window.setScene(scene);
  61. window.show();
  62. }
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement