Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.text.Font;
- import javafx.scene.text.FontWeight;
- import javafx.stage.Stage;
- public class Main extends Application {
- Stage window;
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) throws Exception {
- window = primaryStage;
- window.setTitle("thenewboston - JavaFX");
- //GridPane with 10px padding around edge
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10));
- grid.setVgap(10);
- grid.setHgap(10);
- grid.setAlignment(Pos.CENTER);
- //Name Label - constrains use (child, column, row)
- Label nameLabel = new Label("Username:");
- GridPane.setConstraints(nameLabel, 0, 0);
- nameLabel.setFont(Font.font("Tahoma", FontWeight.LIGHT, 25));
- //Name Input
- TextField nameInput = new TextField("Username");
- GridPane.setConstraints(nameInput, 1, 0);
- //Password Label
- Label passLabel = new Label("Password:");
- GridPane.setConstraints(passLabel, 0, 1);
- //Password Input
- PasswordField passInput = new PasswordField();
- passInput.setPromptText("password");
- GridPane.setConstraints(passInput, 1, 1);
- //Login
- Button loginButton = new Button("Log In");
- GridPane.setConstraints(loginButton, 1, 2);
- //Add everything to grid
- grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);
- loginButton.setOnAction(e -> {
- System.out.println(nameInput.getText());
- });
- Scene scene = new Scene(grid, 800, 600);
- window.setScene(scene);
- window.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement