Advertisement
Guest User

Untitled

a guest
May 17th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.18 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.Insets;
  3. import javafx.geometry.Pos;
  4. import javafx.scene.Scene;
  5. import javafx.scene.control.*;
  6. import javafx.scene.effect.DropShadow;
  7. import javafx.scene.image.Image;
  8. import javafx.scene.image.ImageView;
  9. import javafx.scene.layout.AnchorPane;
  10. import javafx.scene.layout.BorderPane;
  11. import javafx.scene.layout.GridPane;
  12. import javafx.scene.layout.StackPane;
  13. import javafx.scene.paint.Color;
  14. import javafx.scene.shape.Line;
  15. import javafx.scene.shape.Rectangle;
  16. import javafx.scene.text.Text;
  17. import javafx.stage.Stage;
  18.  
  19.  
  20. public class LoginScene extends Application {
  21.  
  22.     public static void main(String[] args) {
  23.         launch(args);
  24.     }
  25.  
  26.     @Override
  27.     public void start(Stage stage) {
  28.         //1. pane
  29.         StackPane stackPane = new StackPane();
  30.  
  31.         //Scene
  32.         Scene scene = new Scene(stackPane,700,450);
  33.  
  34.         //2. pane
  35.         BorderPane borderPaneRectangle = new BorderPane();
  36.  
  37.         //3. pane
  38.         BorderPane borderPane = new BorderPane();
  39.  
  40.         //4. pane
  41.         GridPane gridPane = new GridPane();
  42.         gridPane.setHgap(10);
  43.         gridPane.setVgap(2);
  44.         gridPane.setAlignment(Pos.CENTER);
  45.  
  46.         //5. pane
  47.         GridPane gridPaneHeader = new GridPane();
  48.         gridPaneHeader.setVgap(10);
  49.         gridPaneHeader.setHgap(10);
  50.         gridPaneHeader.setAlignment(Pos.CENTER);
  51.  
  52.         //6. pane
  53.         BorderPane borderPaneHeader = new BorderPane();
  54.         borderPaneHeader.setCenter(gridPaneHeader);
  55.  
  56.         //Text header and dropShadow
  57.         DropShadow ds = new DropShadow();
  58.         ds.setOffsetY(5.0f);
  59.         ds.setColor(Color.color(0.2f, 0.2f, 0.2f));
  60.         Text text = new Text("Greve Kyokushin Karate");
  61.         text.setId("text_header");
  62.         text.setEffect(ds);
  63.         text.setCache(true);
  64.  
  65.         //Logos
  66.         ImageView logo = new ImageView(new Image(getClass().getResourceAsStream("logo.jpg")));
  67.         ImageView calligraphy = new ImageView(new Image(getClass().getResourceAsStream("kaligrafi.jpg")));
  68.         logo.setFitHeight(75);
  69.         logo.setFitWidth(75);
  70.         calligraphy.setFitWidth(50);
  71.         calligraphy.setFitHeight(75);
  72.         AnchorPane anchorPaneLogo = new AnchorPane();
  73.         AnchorPane anchorPaneCalligraphy = new AnchorPane();
  74.         AnchorPane.setLeftAnchor(logo, 20d);
  75.         AnchorPane.setTopAnchor(logo, 20d);
  76.         AnchorPane.setTopAnchor(calligraphy, 20d);
  77.         AnchorPane.setRightAnchor(calligraphy,20d);
  78.         anchorPaneLogo.getChildren().add(logo);
  79.         anchorPaneCalligraphy.getChildren().add(calligraphy);
  80.  
  81.  
  82.         //Labels username and password
  83.         Label label_username = new Label(" Brugernavn:");
  84.         Label label_password = new Label(" Kodeord:");
  85.  
  86.         //Field for username and password
  87.         TextField textField_username = new TextField();
  88.         textField_username.setPromptText("123@gmail.com");
  89.         PasswordField passwordField_password = new PasswordField();
  90.         passwordField_password.setPromptText("*********");
  91.  
  92.         //Button for login
  93.         Button button_login = new Button("Log ind");
  94.         button_login.setId("button_login");
  95.  
  96.         //Lines between nodes in gridPane
  97.         Line line1 = new Line();
  98.         line1.setStartX(0);
  99.         line1.setEndX(400);
  100.         Line line2 = new Line();
  101.         line2.setStartX(0);
  102.         line2.setEndX(400);
  103.  
  104.         //Rectangle behind the gridPane
  105.         Rectangle rectangle = new Rectangle(500,200);
  106.         rectangle.setArcHeight(25);
  107.         rectangle.setArcWidth(25);
  108.         rectangle.setId("rectangle");
  109.  
  110.         //Adding to gridPane for login
  111.         //Adding extra space
  112.         gridPane.setMargin(label_username, new Insets(90,0,0,0));
  113.         gridPane.setMargin(textField_username, new Insets(90,0,0,0));
  114.         gridPane.add(label_username,1,1,1,1);
  115.         gridPane.add(textField_username,2,1,1,1);
  116.         gridPane.add(line1,1,2,2,1);
  117.         //Adding extra space
  118.         gridPane.setMargin(label_password, new Insets(10,0,0,0));
  119.         gridPane.setMargin(passwordField_password, new Insets(10,0,0,0));
  120.         gridPane.add(label_password,1,3);
  121.         gridPane.add(passwordField_password,2,3);
  122.         gridPane.add(line2,1,4,2,1);
  123.         //Adding extra space between button_login and the black line
  124.         gridPane.setMargin(button_login, new Insets(25,0,0,0));
  125.         gridPane.add(button_login,1,5,2,1);
  126.  
  127.         //Adding to gridPaneHeader
  128.         //Adding extra space from the top of the window
  129.         gridPane.setMargin(text, new Insets(50,0,0,0));
  130.         gridPaneHeader.add(text,2,1);
  131.  
  132.         //Adding panes to panes
  133.         borderPaneRectangle.setCenter(rectangle);
  134.         borderPaneRectangle.setTop(borderPaneHeader);
  135.         borderPane.setCenter(gridPane);
  136.         stackPane.getChildren().addAll(borderPaneRectangle, borderPane, anchorPaneLogo, anchorPaneCalligraphy);
  137.  
  138.         // Adding the title to the window (stage)
  139.         stage.setTitle("Log ind");
  140.  
  141.         // Removing resize
  142.         stage.setResizable(false);
  143.        
  144.         // Adding stylesheet
  145.         scene.getStylesheets().add("Stylesheet.css");
  146.        
  147.         return scene;
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement