Guest User

Untitled

a guest
Jun 25th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. package com.reejubhai;
  2. // Created on 6/25/2018.
  3.  
  4.  
  5. import javafx.application.Application;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.*;
  10. import javafx.scene.layout.BorderPane;
  11. import javafx.scene.layout.GridPane;
  12. import javafx.scene.layout.HBox;
  13. import javafx.stage.Stage;
  14.  
  15. public class DropDown extends Application {
  16.  
  17. public static void main(String[] args) {
  18. System.out.println("Launching the application.");
  19. launch(args);
  20. System.out.println("Application executed.\nGoodbye");
  21. }
  22.  
  23.  
  24.  
  25.  
  26. @Override
  27. public void start(Stage primaryStage) {
  28.  
  29. Button button = new Button("Enter");
  30. TextField userText = new TextField();
  31. PasswordField passText = new PasswordField();
  32. Label console1 = new Label();
  33. Label console2 = new Label();
  34. ComboBox<String> dropDown = new ComboBox<>();
  35.  
  36. CheckBox checkBox = new CheckBox("Send Notifications?");
  37. Label username = new Label("Username");
  38. Label password = new Label("Password");
  39.  
  40. Button logIn1 = new Button("Log In");
  41.  
  42. userText.setPromptText("Type your Username");
  43. passText.setPromptText("Type your Password");
  44.  
  45. logIn1.setOnAction(event -> {
  46. System.out.println("The entered username is:" + userText.getText());
  47. System.out.println("The entered password is:" + passText.getText());
  48. userValidate(userText, passText, console1);
  49. loginSite(dropDown, console2);
  50. });
  51.  
  52. dropDown.getItems().addAll("Google", "Facebook", "Twitter", "GitHub");
  53. dropDown.setPadding(new Insets(2,2,2,2));
  54. dropDown.setOnAction(e -> System.out.println(dropDown.getValue()));
  55. dropDown.setPromptText("Login Options");
  56. dropDown.setOnAction(event -> console2.setText("Logging in to " + dropDown.getValue()));
  57.  
  58. HBox box = new HBox();
  59. box.getChildren().add(dropDown);
  60. box.setAlignment(Pos.CENTER);
  61.  
  62. GridPane layout = new GridPane();
  63. GridPane.setConstraints(username,0,0);
  64. GridPane.setConstraints(password,0,1);
  65. GridPane.setConstraints(userText,1,0);
  66. GridPane.setConstraints(passText,1,1);
  67. GridPane.setConstraints(logIn1,1,2);
  68. GridPane.setConstraints(console1,1,4);
  69. GridPane.setConstraints(console2,1,3);
  70.  
  71.  
  72. BorderPane mainLayout = new BorderPane(layout);
  73. mainLayout.setBottom(checkBox);
  74. mainLayout.setTop(box);
  75. mainLayout.setPadding(new Insets(15,15,15,15));
  76.  
  77. layout.setVgap(20);
  78. layout.setHgap(20);
  79. layout.setPadding(new Insets(10,10,10,10));
  80. layout.getChildren().addAll(username, password, logIn1, userText, passText, console1, console2);
  81. layout.setAlignment(Pos.CENTER);
  82.  
  83. button.setOnAction(e -> System.out.println("Item selected:" + checkBox.getText()));
  84.  
  85. Scene scene = new Scene(mainLayout, 400, 400);
  86. primaryStage.setScene(scene);
  87. primaryStage.setTitle("Login");
  88. primaryStage.show();
  89.  
  90. }
  91.  
  92. private void userValidate(TextField userText, TextField passText, Label console1) {
  93. if(userText.getText().equals("reejubhai")) {
  94. if(passText.getText().equals("leftarmchinaman"))
  95. console1.setText("User Logged in");
  96. else
  97. console1.setText("Password is incorrect");
  98. }
  99. else
  100. console1.setText("Username is incorrect");
  101. }
  102.  
  103. private void loginSite(ComboBox<String> dropDown, Label console2) {
  104. if(dropDown.getValue() == null)
  105. console2.setText("Select your desired network.");
  106.  
  107.  
  108. }
  109.  
  110. }
Add Comment
Please, Sign In to add comment