Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package formfxexample;
  7.  
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import javafx.application.Application;
  11. import javafx.event.ActionEvent;
  12. import javafx.geometry.Insets;
  13. import javafx.geometry.Orientation;
  14. import javafx.geometry.Pos;
  15. import javafx.scene.Scene;
  16. import javafx.scene.control.Button;
  17. import javafx.scene.control.Label;
  18. import javafx.scene.control.PasswordField;
  19. import javafx.scene.control.Separator;
  20. import javafx.scene.control.TextField;
  21. import javafx.scene.layout.GridPane;
  22. import javafx.scene.layout.HBox;
  23. import javafx.scene.paint.Color;
  24. import javafx.scene.text.Font;
  25. import javafx.scene.text.FontWeight;
  26. import javafx.scene.text.Text;
  27. import javafx.stage.Stage;
  28.  
  29. /**
  30.  *
  31.  * @author arief
  32.  */
  33. public class FormFXExample extends Application {
  34.     String fontName = "Comic Sans MS";
  35.     String name,password;
  36.    
  37.     @Override
  38.     public void start(Stage primaryStage){
  39.        
  40.         GridPane root = new GridPane();
  41.        
  42.         root.setAlignment(Pos.CENTER);
  43.         root.setHgap(10);
  44.         root.setVgap(10);
  45.         root.setPadding(new Insets(25, 25, 25, 25));
  46.         root.setId("grid");
  47.        
  48.         Text sceneTitle = new Text("Welcome");
  49.         sceneTitle.setFont(Font.font(fontName,FontWeight.NORMAL,20));
  50.         root.add(sceneTitle, 0, 0, 2, 1);
  51.        
  52.         Label userName = new Label("Username:");
  53.         userName.setFont(Font.font(fontName,FontWeight.NORMAL,12));
  54.         root.add(userName, 0, 1);
  55.        
  56.         TextField userBox = new TextField();
  57.         userBox.setFont(Font.font(fontName,FontWeight.NORMAL, 12));
  58.         root.add(userBox, 1, 1);
  59.        
  60.         Label pw = new Label("Password:");
  61.         pw.setFont(Font.font(fontName,FontWeight.NORMAL,12));
  62.         root.add(pw, 0, 2);
  63.        
  64.         PasswordField pwBox = new PasswordField();
  65.         root.add(pwBox, 1, 2);
  66.        
  67.         Button btn = new Button("Sign In");
  68.         btn.setFont(Font.font(fontName,FontWeight.NORMAL,12));
  69.        
  70.         Button btnClose = new Button("Close");
  71.         btnClose.setFont(Font.font(fontName,FontWeight.NORMAL,12));
  72.        
  73.         Separator spt = new Separator(Orientation.HORIZONTAL);
  74.         root.add(spt, 1, 3);
  75.        
  76.         HBox hbBtn = new HBox(10);
  77.         hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  78.         hbBtn.getChildren().addAll(btn,btnClose);
  79.         root.add(hbBtn,1,4);
  80.        
  81.         final Text actionTarget = new Text();
  82.         actionTarget.setFont(Font.font(fontName, FontWeight.NORMAL, 12));
  83.         root.add(actionTarget, 1, 6);
  84.        
  85.         //root.setGridLinesVisible(true);
  86.         //btn.setStyle("-fx-color:lightblue;");
  87.         //btnClose.setStyle("-fx-color:lightblue;");
  88.         //spt.setStyle("-fx-background:black;");
  89.         //root.setStyle("-fx-background:whitesmoke;");
  90.        
  91.         btn.setOnAction((ActionEvent event) -> {
  92.         name = userBox.getText();
  93.         password = pwBox.getText();
  94.             if (name.equals("") && password.equals("")){
  95.                 actionTarget.setFill(Color.FIREBRICK);
  96.                 actionTarget.setText("Username & Password field can not empty!");
  97.             }else if (name.equals("")){
  98.                 actionTarget.setFill(Color.FIREBRICK);
  99.                 actionTarget.setText("Username field can not empty!");
  100.                
  101.             }else if (password.equals("")){
  102.                 actionTarget.setFill(Color.FIREBRICK);
  103.                 actionTarget.setText("Password field can not empty!");
  104.                
  105.            }else if (name.equals("admin") && password.equals("admin")){
  106.                 try {
  107.                     CSSExample cssexam = new CSSExample();
  108.                     cssexam.start(primaryStage);
  109.                     cssexam.greeting = name;
  110.                 } catch (Exception ex) {
  111.                     Logger.getLogger(FormFXExample.class.getName()).log(Level.SEVERE, null, ex);
  112.                 }
  113.                    
  114.             }else{
  115.                     actionTarget.setFill(Color.FIREBRICK);
  116.                     actionTarget.setText("Can't open CSSExample Window");
  117.             }
  118.            
  119.         });
  120.        
  121.         btnClose.setOnAction((ActionEvent event) -> {
  122.             primaryStage.close();
  123.         });
  124.        
  125.        
  126.         Scene scene = new Scene(root, 400, 400);
  127.         scene.getStylesheets().add(FormFXExample.class.getResource("asset/Login.css").toExternalForm());
  128.         primaryStage.setTitle("Welcome FXLogin");
  129.         primaryStage.setScene(scene);
  130.         primaryStage.setX(484);
  131.         primaryStage.setY(256);
  132.         primaryStage.show();
  133.     }
  134.  
  135.     /**
  136.      * @param args the command line arguments
  137.      */
  138.     public static void main(String[] args) {
  139.         launch(args);
  140.     }
  141.    
  142. }