Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javafx.application.Application;
  4. import javafx.scene.layout.GridPane;
  5. import javafx.stage.Stage;
  6.  
  7. import java.awt.*;
  8.  
  9. public class Main extends Application {
  10.  
  11.     Stage window;
  12.  
  13.     public static void main(String[] args){
  14.         launch(args);
  15.     }
  16.  
  17.     @Override
  18.     public void start(Stage primaryStage) throws Exception {
  19.         window = primaryStage;
  20.         window.setTitle("Learn from the Book");
  21.         window.setScene(new LoginScene());
  22.         window.setMinWidth(320);
  23.         window.setMinHeight(240);
  24.         window.show();
  25.     }
  26. }
  27.  
  28.  */
  29. public class LoginScene extends Scene{
  30.     GridPane grid = new GridPane();
  31.     GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
  32.     private double scale = 0.3;
  33.     private double width = gd.getDisplayMode().getWidth() * scale ;
  34.     private double height = gd.getDisplayMode().getHeight() * scale;
  35.  
  36.  
  37.     public LoginScene(){
  38.         super(new GridPane(),100,100);
  39.         setGridLogin();
  40.     }
  41.  
  42.     private void setGridLogin(){
  43.         grid.setPadding(new Insets(10));
  44.         grid.setAlignment(Pos.CENTER);
  45.         grid.setVgap(8);
  46.         grid.setHgap(10);
  47.  
  48.         Label nameLabel = new Label("Username:");
  49.         GridPane.setConstraints(nameLabel,0,0);
  50.  
  51.         Label passLabel = new Label("Password:");
  52.         GridPane.setConstraints(passLabel,0,1);
  53.  
  54.         TextField nameInput = new TextField();
  55.         nameInput.setPromptText("username");
  56.         GridPane.setConstraints(nameInput,1,0);
  57.  
  58.         TextField passInput = new TextField();
  59.         passInput.setPromptText("password");
  60.         GridPane.setConstraints(passInput,1,1);
  61.  
  62.         Button loginButton = new Button("Log in");
  63.         GridPane.setConstraints(loginButton,1,2);
  64.         //loginButton.setOnAction(e -> switchScene(passInput.getText(),nameInput.getText()));
  65.  
  66.         grid.getChildren().addAll(nameLabel,nameInput,passInput,passLabel,loginButton);
  67.  
  68.         Scene scene = new Scene(grid,width,height);
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement