Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  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 project_netbeans;
  7.  
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. import javafx.application.Application;
  11. import javafx.event.ActionEvent;
  12. import javafx.event.EventHandler;
  13. import javafx.geometry.Insets;
  14. import javafx.geometry.Pos;
  15. import javafx.scene.Node;
  16. import javafx.scene.Scene;
  17. import javafx.scene.control.Alert;
  18. import javafx.scene.control.Button;
  19. import javafx.scene.control.Label;
  20. import javafx.scene.control.TextField;
  21. import javafx.scene.image.Image;
  22. import javafx.scene.image.ImageView;
  23. import javafx.scene.layout.BorderPane;
  24. import javafx.scene.layout.GridPane;
  25. import javafx.scene.layout.StackPane;
  26. import javafx.stage.Modality;
  27. import javafx.stage.Stage;
  28.  
  29. /**
  30. *
  31. * @author 115465872
  32. */
  33. public class NewCorporateCustomer {
  34.  
  35. public static void display()
  36. {
  37.  
  38. Stage primaryStage = new Stage();
  39. primaryStage.setTitle("Register new customer");
  40.  
  41. BorderPane pane = new BorderPane();
  42. pane.setStyle("-fx-padding: 10; -fx-background-color: #28ABE3" );
  43.  
  44. //here we are creating a new image which will be our create new logo
  45. Image image = new Image("Image/NewCust.png");
  46. StackPane LogoBackGround = new StackPane(); //create a new stack pane to hold this image and allow us
  47. //to center it within the border top pane
  48. LogoBackGround.setPrefSize(75,75);//setting the size we want
  49.  
  50. ImageView Logo = new ImageView(image); //creating a new image view that will be used
  51. Logo.setFitHeight(75); //fitting the image to the image view
  52. Logo.setFitWidth(75);
  53.  
  54. LogoBackGround.setPadding(new Insets(30,0,0,0));
  55. LogoBackGround.getChildren().add(Logo); //adding the logo to the stack pane
  56.  
  57. pane.setTop(LogoBackGround); //adding the stack pane to the top region of the borderpane
  58. pane.setCenter(CenterLayout());
  59. pane.setAlignment(CenterLayout(),Pos.CENTER);
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. Scene scene = new Scene(pane);
  82. primaryStage.setResizable(false);
  83. primaryStage.setScene(scene);
  84. primaryStage.initModality(Modality.APPLICATION_MODAL);
  85. primaryStage.showAndWait();
  86. }
  87.  
  88. private static StackPane CenterLayout(){
  89. StackPane CenterPane = new StackPane();
  90. CenterPane.setStyle("-fx-Background-color: White; -fx-border-color:Black;");
  91. TextField tfName = new TextField();
  92. TextField tfEmail = new TextField();
  93. TextField tfAddress = new TextField();
  94. Button Registerbutton = new Button("Register Customer");
  95. Button CancelButton = new Button("Cancel");
  96.  
  97. GridPane p1 = new GridPane();
  98. p1.setAlignment(Pos.CENTER);
  99. p1.setHgap(5);
  100. p1.setVgap(5);
  101. p1.add(new Label("Name:"),0, 0);
  102. p1.add(new Label("Email:"), 0, 1);
  103. p1.add(new Label("Address:"),0,2);
  104. p1.add(tfName, 1, 0);
  105. p1.add(tfEmail, 1, 1);
  106. p1.add(tfAddress,1,2);
  107. p1.add(Registerbutton, 0, 3);
  108. p1.add(CancelButton, 1, 3);
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. Registerbutton.setOnAction(e ->
  116. {
  117.  
  118. Pattern p = Pattern.compile("[a-zA-Z]");
  119. Matcher m = p.matcher(tfName.getText());
  120. Pattern p2 = Pattern.compile("[a-zA-Z0-9][a-zA-Z0-9._]*@[a-zA-Z0-9]+([.][a-zA-Z]+)+");
  121. Matcher m1 = p2.matcher(tfEmail.getText());
  122. if((m.find() && m.group().equals(tfName.getText())) | (m1.find() && m1.group().equals(tfEmail.getText()))){
  123.  
  124. ((Node)e.getSource()).getScene().getWindow().hide();
  125. }
  126. else
  127. {
  128. Alert alert = new Alert(Alert.AlertType.WARNING);
  129. alert.setTitle("Validate Fields");
  130. alert.setHeaderText(null);
  131. alert.setContentText("Please complete all fields");
  132. alert.showAndWait();
  133.  
  134. }
  135.  
  136. }
  137.  
  138.  
  139. );
  140. CancelButton.setOnAction(e ->
  141. {
  142.  
  143. tfName.clear();
  144. tfEmail.clear();
  145. tfAddress.clear();
  146. ((Node)e.getSource()).getScene().getWindow().hide();
  147.  
  148. }
  149.  
  150. );
  151.  
  152. CenterPane.getChildren().add(p1);
  153.  
  154. return CenterPane;
  155. }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement