Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package project_netbeans;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Node;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- /**
- *
- * @author 115465872
- */
- public class NewCorporateCustomer {
- public static void display()
- {
- Stage primaryStage = new Stage();
- primaryStage.setTitle("Register new customer");
- BorderPane pane = new BorderPane();
- pane.setStyle("-fx-padding: 10; -fx-background-color: #28ABE3" );
- //here we are creating a new image which will be our create new logo
- Image image = new Image("Image/NewCust.png");
- StackPane LogoBackGround = new StackPane(); //create a new stack pane to hold this image and allow us
- //to center it within the border top pane
- LogoBackGround.setPrefSize(75,75);//setting the size we want
- ImageView Logo = new ImageView(image); //creating a new image view that will be used
- Logo.setFitHeight(75); //fitting the image to the image view
- Logo.setFitWidth(75);
- LogoBackGround.setPadding(new Insets(30,0,0,0));
- LogoBackGround.getChildren().add(Logo); //adding the logo to the stack pane
- pane.setTop(LogoBackGround); //adding the stack pane to the top region of the borderpane
- pane.setCenter(CenterLayout());
- pane.setAlignment(CenterLayout(),Pos.CENTER);
- Scene scene = new Scene(pane);
- primaryStage.setResizable(false);
- primaryStage.setScene(scene);
- primaryStage.initModality(Modality.APPLICATION_MODAL);
- primaryStage.showAndWait();
- }
- private static StackPane CenterLayout(){
- StackPane CenterPane = new StackPane();
- CenterPane.setStyle("-fx-Background-color: White; -fx-border-color:Black;");
- TextField tfName = new TextField();
- TextField tfEmail = new TextField();
- TextField tfAddress = new TextField();
- Button Registerbutton = new Button("Register Customer");
- Button CancelButton = new Button("Cancel");
- GridPane p1 = new GridPane();
- p1.setAlignment(Pos.CENTER);
- p1.setHgap(5);
- p1.setVgap(5);
- p1.add(new Label("Name:"),0, 0);
- p1.add(new Label("Email:"), 0, 1);
- p1.add(new Label("Address:"),0,2);
- p1.add(tfName, 1, 0);
- p1.add(tfEmail, 1, 1);
- p1.add(tfAddress,1,2);
- p1.add(Registerbutton, 0, 3);
- p1.add(CancelButton, 1, 3);
- Registerbutton.setOnAction(e ->
- {
- Pattern p = Pattern.compile("[a-zA-Z]");
- Matcher m = p.matcher(tfName.getText());
- Pattern p2 = Pattern.compile("[a-zA-Z0-9][a-zA-Z0-9._]*@[a-zA-Z0-9]+([.][a-zA-Z]+)+");
- Matcher m1 = p2.matcher(tfEmail.getText());
- if((m.find() && m.group().equals(tfName.getText())) | (m1.find() && m1.group().equals(tfEmail.getText()))){
- ((Node)e.getSource()).getScene().getWindow().hide();
- }
- else
- {
- Alert alert = new Alert(Alert.AlertType.WARNING);
- alert.setTitle("Validate Fields");
- alert.setHeaderText(null);
- alert.setContentText("Please complete all fields");
- alert.showAndWait();
- }
- }
- );
- CancelButton.setOnAction(e ->
- {
- tfName.clear();
- tfEmail.clear();
- tfAddress.clear();
- ((Node)e.getSource()).getScene().getWindow().hide();
- }
- );
- CenterPane.getChildren().add(p1);
- return CenterPane;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement