Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package view;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import controller.databaseConnection;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- import model.Player;
- public class RegisterScreen extends Gui {
- Pane registerPane = new Pane();
- Scene registerScene = new Scene(registerPane, 600, 400);
- TextField usernameField = new TextField();
- PasswordField userPasswordField = new PasswordField();
- Pane loginPane = new Pane();
- MainMenuScreen menu;
- public void makeRegisterScreen(Stage primaryStage) {
- registerPane.getStyleClass().add("loginAndRegister");
- primaryStage.centerOnScreen();
- registerScene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
- registerPane.getStyleClass().add("paneWithWallpaper");
- primaryStage.setScene(registerScene);
- Text warningText = new Text();
- registerPane.getChildren().add(warningText);
- warningText.setTranslateX(320);
- warningText.setTranslateY(125);
- warningText.setWrappingWidth(200);
- warningText.setFill(Color.RED);
- registerPane.getChildren().add(usernameField);
- usernameField.setPromptText("Naam");
- usernameField.setTranslateX(100);
- usernameField.setTranslateY(100);
- usernameField.setPrefSize(200, 50);
- registerPane.getChildren().add(userPasswordField);
- userPasswordField.setPromptText("Wachtwoord");
- userPasswordField.setTranslateX(100);
- userPasswordField.setTranslateY(200);
- userPasswordField.setPrefSize(200, 50);
- databaseConnection dbcon = new databaseConnection("jdbc:mysql://databases.aii.avans.nl/sficken_db", "sficken",
- "Ab12345");
- Button finishRegistrationButton = new Button("Registreren");
- finishRegistrationButton.getStyleClass().add("button");
- setGlobalEventHandler(registerPane, finishRegistrationButton);
- registerPane.getChildren().add(finishRegistrationButton);
- finishRegistrationButton.setPrefSize(150, 40);
- finishRegistrationButton.setTranslateX(450);
- finishRegistrationButton.setTranslateY(350);
- finishRegistrationButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
- Matcher m = p.matcher(usernameField.getText());
- if (!usernameField.getText().trim().isEmpty() && !userPasswordField.getText().trim().isEmpty()
- && usernameField.getText().length() <= 25 && userPasswordField.getText().length() <= 25 && dbcon
- .select("SELECT username FROM account WHERE username='" + usernameField.getText() + "'",
- "username")
- .isEmpty() && !m.matches() && (usernameField.getText().length() >= 3)) {
- dbcon.insert("INSERT INTO account VALUES ('" + usernameField.getText() + "' , '"
- + userPasswordField.getText() + "')");
- player.setName(usernameField.getText());
- menu = new MainMenuScreen();
- menu.makeMainMenuScreen(primaryStage);
- loginPane.getChildren().add(usernameField);
- loginPane.getChildren().add(userPasswordField);
- warningText.setText(" ");
- usernameField.getStyleClass().removeAll("redTextField");
- userPasswordField.getStyleClass().removeAll("redTextField");
- } else if (!dbcon
- .select("SELECT username FROM account WHERE username='" + usernameField.getText() + "'",
- "username")
- .isEmpty()) {
- usernameField.getStyleClass().add("redTextField");
- warningText.setText("Deze gebruikersnaam is al in gebruik");
- } else if (usernameField.getText().length() > 25) {
- usernameField.getStyleClass().add("redTextField");
- warningText.setWrappingWidth(200);
- warningText.setText("Gebruikersnaam moet minder dan 25 karakters zijn");
- }
- else if (m.find()) {
- warningText.setText("Gebruikersnaam mag geen speciale karakters bevatten.");
- System.out.println("CHARACTER DETECTED");
- usernameField.getStyleClass().add("redTextField");
- } else if (usernameField.getText().length() < 3) {
- warningText.setText("Gebruikersnaam moet op zijn minst 3 lang zijn.");
- System.out.println("TOO SHORT");
- usernameField.getStyleClass().add("redTextField");
- }
- else {
- if (usernameField.getText().trim().isEmpty()) {
- usernameField.getStyleClass().add("redTextField");
- }
- if (userPasswordField.getText().trim().isEmpty()) {
- userPasswordField.getStyleClass().add("redTextField");
- }
- }
- }
- });
- Button backButton = new Button("Terug");
- backButton.getStyleClass().add("button");
- registerPane.getChildren().add(backButton);
- backButton.setPrefSize(150, 40);
- backButton.setTranslateX(0);
- backButton.setTranslateY(350);
- backButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- login = new LoginScreen();
- login.makeLoginScreen(primaryStage);
- usernameField.setStyle(null);
- userPasswordField.setStyle(null);
- }
- });
- primaryStage.show();
- primaryStage.setFullScreen(false);
- primaryStage.setResizable(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement