Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.hva.fonlc;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- 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.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- /**
- *
- * @author lennardf1989
- */
- public class MainApplication extends Application {
- @Override
- public void start(Stage primaryStage) {
- BorderPane root = new BorderPane();
- //Center
- VBox centerBox = new VBox();
- centerBox.setStyle("-fx-max-width:200px;-fx-alignment:center");
- Label statusLabel = new Label();
- statusLabel.setVisible(false);
- centerBox.getChildren().add(statusLabel);
- Label userNameLabel = new Label("Username");
- centerBox.getChildren().add(userNameLabel);
- TextField userNameTextField = new TextField();
- centerBox.getChildren().add(userNameTextField);
- Label passwordLabel = new Label("Password");
- centerBox.getChildren().add(passwordLabel);
- PasswordField passwordTextField = new PasswordField();
- centerBox.getChildren().add(passwordTextField);
- root.setCenter(centerBox);
- //Bottom
- HBox bottomBox = new HBox();
- bottomBox.setAlignment(Pos.BASELINE_RIGHT);
- bottomBox.setStyle("-fx-padding:20px");
- Button loginButton = new Button("Login");
- loginButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- statusLabel.setVisible(true);
- boolean userName = false;
- boolean password = false;
- if(userNameTextField.getText().equals("")) {
- userNameLabel.setStyle("-fx-text-fill:red");
- }
- else {
- userNameLabel.setStyle("-fx-text-fill:inherit");
- userName = true;
- }
- if(passwordTextField.getText().equals("")) {
- passwordLabel.setStyle("-fx-text-fill:red");
- }
- else {
- passwordLabel.setStyle("-fx-text-fill:inherit");
- password = true;
- }
- if(userName && password) {
- statusLabel.setText("You are logged in!");
- }
- else {
- statusLabel.setText("Username and password are both required!");
- }
- }
- });
- bottomBox.getChildren().add(loginButton);
- root.setBottom(bottomBox);
- //Scene
- Scene scene = new Scene(root, 640, 480);
- //Window
- primaryStage.setTitle("Hello World!");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement