Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.  
  2. package guitutorial02;
  3.  
  4. import javafx.geometry.Insets;
  5. import javafx.application.Application;
  6. import javafx.event.ActionEvent;
  7. import javafx.event.EventHandler;
  8. import javafx.geometry.Pos;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.Button;
  11. import javafx.scene.control.Label;
  12. import javafx.scene.control.PasswordField;
  13. import javafx.scene.control.TextField;
  14. import javafx.scene.layout.GridPane;
  15. import javafx.scene.layout.HBox;
  16. import javafx.scene.layout.StackPane;
  17. import javafx.scene.paint.Color;
  18. import javafx.scene.text.Font;
  19. import javafx.scene.text.FontWeight;
  20. import javafx.scene.text.Text;
  21. import javafx.stage.Stage;
  22. public class GUITutorial02 extends Application {
  23.  
  24.     @Override
  25.     public void start(Stage primaryStage) {
  26.         primaryStage.setTitle("JavaFX Welcome");
  27.         GridPane grid = new GridPane();
  28.         grid.setAlignment(Pos.CENTER);
  29.         grid.setHgap(10);
  30.         grid.setVgap(10);
  31.         grid.setPadding(new Insets(25, 25, 25, 25));
  32.  
  33.         Text scenetitle = new Text("Welcome");
  34.         scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
  35.         grid.add(scenetitle, 0, 0, 2, 1);
  36.  
  37.         Label userName = new Label("User Name:");
  38.         grid.add(userName, 0, 1);
  39.  
  40.         TextField userTextField = new TextField();
  41.         grid.add(userTextField, 1, 1);
  42.  
  43.         Label pw = new Label("Password:");
  44.         grid.add(pw, 0, 2);
  45.  
  46.         PasswordField pwBox = new PasswordField();
  47.         grid.add(pwBox, 1, 2);
  48.  
  49.         Button btn = new Button("Sign in");
  50.         HBox hbBtn = new HBox(10);
  51.         hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  52.         hbBtn.getChildren().add(btn);
  53.         grid.add(hbBtn, 1, 4);
  54.  
  55.         final Text actiontarget = new Text();
  56.         grid.add(actiontarget, 1, 6);
  57.  
  58.         btn.setOnAction(new EventHandler<ActionEvent>() {
  59.  
  60.             @Override
  61.             public void handle(ActionEvent e) {
  62.                 actiontarget.setFill(Color.FIREBRICK);
  63.                 actiontarget.setText("Sign in button pressed");
  64.             }
  65.         });
  66.  
  67.         Scene scene = new Scene(grid, 300, 275);
  68.         primaryStage.setScene(scene);
  69.         scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
  70.         primaryStage.show();
  71.     }
  72.     ;
  73.        
  74.     StackPane root = new StackPane();
  75.     Scene scene = new Scene(root, 300, 250);
  76.  
  77.     public static void main(String[] args) {
  78.         launch(args);
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement