Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.reejubhai;
- // Created on 6/25/2018.
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.stage.Stage;
- public class DropDown extends Application {
- public static void main(String[] args) {
- System.out.println("Launching the application.");
- launch(args);
- System.out.println("Application executed.\nGoodbye");
- }
- @Override
- public void start(Stage primaryStage) {
- Button button = new Button("Enter");
- TextField userText = new TextField();
- PasswordField passText = new PasswordField();
- Label console1 = new Label();
- Label console2 = new Label();
- ComboBox<String> dropDown = new ComboBox<>();
- CheckBox checkBox = new CheckBox("Send Notifications?");
- Label username = new Label("Username");
- Label password = new Label("Password");
- Button logIn1 = new Button("Log In");
- userText.setPromptText("Type your Username");
- passText.setPromptText("Type your Password");
- logIn1.setOnAction(event -> {
- System.out.println("The entered username is:" + userText.getText());
- System.out.println("The entered password is:" + passText.getText());
- userValidate(userText, passText, console1);
- loginSite(dropDown, console2);
- });
- dropDown.getItems().addAll("Google", "Facebook", "Twitter", "GitHub");
- dropDown.setPadding(new Insets(2,2,2,2));
- dropDown.setOnAction(e -> System.out.println(dropDown.getValue()));
- dropDown.setPromptText("Login Options");
- dropDown.setOnAction(event -> console2.setText("Logging in to " + dropDown.getValue()));
- HBox box = new HBox();
- box.getChildren().add(dropDown);
- box.setAlignment(Pos.CENTER);
- GridPane layout = new GridPane();
- GridPane.setConstraints(username,0,0);
- GridPane.setConstraints(password,0,1);
- GridPane.setConstraints(userText,1,0);
- GridPane.setConstraints(passText,1,1);
- GridPane.setConstraints(logIn1,1,2);
- GridPane.setConstraints(console1,1,4);
- GridPane.setConstraints(console2,1,3);
- BorderPane mainLayout = new BorderPane(layout);
- mainLayout.setBottom(checkBox);
- mainLayout.setTop(box);
- mainLayout.setPadding(new Insets(15,15,15,15));
- layout.setVgap(20);
- layout.setHgap(20);
- layout.setPadding(new Insets(10,10,10,10));
- layout.getChildren().addAll(username, password, logIn1, userText, passText, console1, console2);
- layout.setAlignment(Pos.CENTER);
- button.setOnAction(e -> System.out.println("Item selected:" + checkBox.getText()));
- Scene scene = new Scene(mainLayout, 400, 400);
- primaryStage.setScene(scene);
- primaryStage.setTitle("Login");
- primaryStage.show();
- }
- private void userValidate(TextField userText, TextField passText, Label console1) {
- if(userText.getText().equals("reejubhai")) {
- if(passText.getText().equals("leftarmchinaman"))
- console1.setText("User Logged in");
- else
- console1.setText("Password is incorrect");
- }
- else
- console1.setText("Username is incorrect");
- }
- private void loginSite(ComboBox<String> dropDown, Label console2) {
- if(dropDown.getValue() == null)
- console2.setText("Select your desired network.");
- }
- }
Add Comment
Please, Sign In to add comment