librejack

Blackjack clone written in java
git clone https://github.com/michaelneuper/librejack.git
README | Files | Log | Refs | LICENSE

commit 7d67eeb33b4ccb88333362bb58aac0fbd5b72c4d
parent d5d798a276355474fb810eeacac14b7f0ec5e57d
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Sun, 12 Feb 2023 17:34:32 +0200

Add checks for email, number and password

Diffstat:
Asrc/controller/LoginController.java | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/view/LoginGUI.form | 216+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/view/LoginGUI.java | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 575 insertions(+), 25 deletions(-)

diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java @@ -0,0 +1,165 @@ +package controller; + +import java.util.regex.Pattern; +import javax.swing.JOptionPane; + +/** + * + * @author Michael + */ +public class LoginController { + + public LoginController() { + } + + public boolean areAllFieldsValid(String email, String mobileNumber, String password) { + return +// isValidEmail(email) && + isValidSouthAfricanMobileNumber(mobileNumber) && + isValidPassword(password); + } + + /** + * Determines whether a given email is a valid email format according to the following criteria: + * - The email must contain a username and a domain separated by an @ symbol. + * - The username may contain alphanumeric characters, underscores, plus signs, asterisks, and hyphens. + * - The domain must consist of one or more subdomains separated by periods, and end in a top-level domain (TLD) + * of two to seven letters. + * + * @param email the email to be validated + * @return true if the email is a valid email format, false otherwise + */ + private boolean isValidEmail(String email) { + String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + + "[a-zA-Z0-9_+&*-]+)*@" + + "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; // regular expression representing a valid email + Pattern pattern = Pattern.compile(emailRegex); + + boolean isValid = pattern.matcher(email).matches(); + + if (!isValid) { + JOptionPane.showMessageDialog(null, "Please enter a valid email"); + } + + return isValid; + } + + /** + * Checks whether a given mobile number is a valid South African mobile number. + * + * @param mobileNumber the mobile number to check + * @return true if the mobile number is a valid South African mobile number, false otherwise + */ + private boolean isValidSouthAfricanMobileNumber(String mobileNumber) { + // Remove any non-digit characters from the mobile number + mobileNumber = mobileNumber.replaceAll("[^\\d]", ""); + + // Check if the mobile number is of the correct length + if (mobileNumber.length() != 10) { + JOptionPane.showMessageDialog(null, "Your mobile number is too short"); + return false; + } + + // Check if the mobile number starts with a valid South African country code + String[] validCountryCodes = {"+27", "27", "0"}; + boolean validCountryCode = false; + for (String code : validCountryCodes) { + if (mobileNumber.startsWith(code)) { + validCountryCode = true; + break; + } + } + if (!validCountryCode) { + JOptionPane.showMessageDialog(null, "Your country code is not South African"); + return false; + } + + // If all checks pass, the mobile number is considered valid + return true; + } + + /** + * Checks the following conditions to determine whether a password is valid: + * - is at least 10 characters in length + * - has at least 1 special character + * - has at least 1 number + * - has at least 1 uppercase and lowercase letter + * + * @param password to be validated + * @return whether password is valid + */ + private boolean isValidPassword(String password) { + if (password == null || password.isEmpty() || password.length() < 10) { + JOptionPane.showMessageDialog(null, "Password must be at least 10 characters long"); + return false; + } + + boolean hasUpperCase = false; + boolean hasLowerCase = false; + boolean hasNumber = false; + boolean hasSpecialChar = false; + + for (int i = 0; i < password.length(); i++) { + char ch = password.charAt(i); + switch (ch) { + case '!': + case '@': + case '#': + case '$': + case '%': + case '^': + case '&': + case '*': + case '(': + case ')': + case '-': + case '+': + case '=': + case '[': + case ']': + case '{': + case '}': + case '|': + case '\\': + case ';': + case ':': + case '\'': + case '\"': + case ',': + case '<': + case '.': + case '>': + case '/': + case '?': + hasSpecialChar = true; + break; + default: + if (Character.isUpperCase(ch)) { + hasUpperCase = true; + } else if (Character.isLowerCase(ch)) { + hasLowerCase = true; + } else if (Character.isDigit(ch)) { + hasNumber = true; + } + break; + } + } + + if (!hasUpperCase) { + JOptionPane.showMessageDialog(null, "Password must contain at least one uppercase letter"); + } + if (!hasLowerCase) { + JOptionPane.showMessageDialog(null, "Password must contain at least one lowercase letter"); + } + if (!hasNumber) { + JOptionPane.showMessageDialog(null, "Password must contain at least one number"); + } + if (!hasSpecialChar) { + JOptionPane.showMessageDialog(null, "Password must contain at least one special character"); + } + + return hasUpperCase && hasLowerCase && hasNumber && hasSpecialChar; + } + + +} diff --git a/src/view/LoginGUI.form b/src/view/LoginGUI.form @@ -3,9 +3,6 @@ <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Properties> <Property name="defaultCloseOperation" type="int" value="3"/> - <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> - <Dimension value="[1258, 809]"/> - </Property> </Properties> <SyntheticProperties> <SyntheticProperty name="formSizePolicy" type="int" value="1"/> @@ -26,13 +23,222 @@ <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> - <EmptySpace min="0" pref="947" max="32767" attributes="0"/> + <Group type="102" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="-2" pref="335" max="-2" attributes="0"/> + <Component id="jLabelWelcome" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="60" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabel1" alignment="0" min="-2" pref="137" max="-2" attributes="0"/> + <Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelPasswordRequirements" alignment="0" min="-2" pref="205" max="-2" attributes="0"/> + <Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelPassword" alignment="0" min="-2" max="-2" attributes="0"/> + <Group type="102" alignment="0" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabelLogin" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelUsername" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelEmail" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelMobileNumber" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelDateOfBirth" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace min="-2" pref="95" max="-2" attributes="0"/> + <Group type="103" groupAlignment="1" attributes="0"> + <Group type="103" groupAlignment="0" max="-2" attributes="0"> + <Component id="jTextFieldUsername" pref="215" max="32767" attributes="0"/> + <Component id="jTextFieldEmail" alignment="0" max="32767" attributes="0"/> + <Component id="jTextFieldMobileNumber" alignment="0" max="32767" attributes="0"/> + </Group> + <Component id="jPasswordField" min="-2" pref="215" max="-2" attributes="0"/> + </Group> + </Group> + <Component id="jButtonVerify" alignment="0" min="-2" pref="204" max="-2" attributes="0"/> + </Group> + </Group> + </Group> + <EmptySpace pref="329" max="32767" attributes="0"/> + </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> - <EmptySpace min="0" pref="664" max="32767" attributes="0"/> + <Group type="102" alignment="1" attributes="0"> + <EmptySpace min="-2" pref="33" max="-2" attributes="0"/> + <Component id="jLabelWelcome" min="-2" pref="105" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="7" max="-2" attributes="0"/> + <Component id="jLabelLogin" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelUsername" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jTextFieldUsername" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelEmail" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jTextFieldEmail" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelMobileNumber" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jTextFieldMobileNumber" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jLabel5" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="29" max="-2" attributes="0"/> + <Component id="jLabelDateOfBirth" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelPassword" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jPasswordField" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace min="-2" pref="18" max="-2" attributes="0"/> + <Component id="jLabelPasswordRequirements" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="jLabel2" min="-2" max="-2" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="jLabel3" min="-2" max="-2" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="jLabel4" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="74" max="-2" attributes="0"/> + <Component id="jButtonVerify" min="-2" pref="86" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="68" max="-2" attributes="0"/> + </Group> </Group> </DimensionLayout> </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabelWelcome"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="48" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="WELCOME TO LIBREJACK!"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelLogin"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="36" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Login"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelEmail"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="18" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Email:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelMobileNumber"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="18" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Mobile number:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelUsername"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="18" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Username:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelPassword"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="18" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Password:"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="jTextFieldUsername"> + <Properties> + <Property name="text" type="java.lang.String" value="PenguinPancakes69"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextFieldUsernameActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JPasswordField" name="jPasswordField"> + <Properties> + <Property name="text" type="java.lang.String" value="password123"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jPasswordFieldActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JLabel" name="jLabelPasswordRequirements"> + <Properties> + <Property name="text" type="java.lang.String" value="Password requires at least:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="text" type="java.lang.String" value="- 10 characters"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel2"> + <Properties> + <Property name="text" type="java.lang.String" value="- 1 uppercase and lowercase letter"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel3"> + <Properties> + <Property name="text" type="java.lang.String" value="- 1 number"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel4"> + <Properties> + <Property name="text" type="java.lang.String" value="- 1 special character"/> + </Properties> + </Component> + <Component class="javax.swing.JButton" name="jButtonVerify"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="48" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="PLAY"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonVerifyActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JTextField" name="jTextFieldEmail"> + <Properties> + <Property name="text" type="java.lang.String" value="johndoe@example.com"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="jTextFieldMobileNumber"> + <Properties> + <Property name="text" type="java.lang.String" value="082 738 9016"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextFieldMobileNumberActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JLabel" name="jLabel5"> + <Properties> + <Property name="text" type="java.lang.String" value="Must be a valid South African number"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelDateOfBirth"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Dialog" size="18" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Date of birth:"/> + </Properties> + </Component> + </SubComponents> </Form> diff --git a/src/view/LoginGUI.java b/src/view/LoginGUI.java @@ -1,24 +1,10 @@ -/* - * Copyright (C) 2023 michael - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ package view; +import controller.LoginController; + /** * - * @author michael + * @author Michael */ public class LoginGUI extends javax.swing.JFrame { @@ -28,6 +14,8 @@ public class LoginGUI extends javax.swing.JFrame { public LoginGUI() { initComponents(); } + + LoginController controller = new LoginController(); /** * This method is called from within the constructor to initialize the form. @@ -38,23 +26,196 @@ public class LoginGUI extends javax.swing.JFrame { // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { + jLabelWelcome = new javax.swing.JLabel(); + jLabelLogin = new javax.swing.JLabel(); + jLabelEmail = new javax.swing.JLabel(); + jLabelMobileNumber = new javax.swing.JLabel(); + jLabelUsername = new javax.swing.JLabel(); + jLabelPassword = new javax.swing.JLabel(); + jTextFieldUsername = new javax.swing.JTextField(); + jPasswordField = new javax.swing.JPasswordField(); + jLabelPasswordRequirements = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jButtonVerify = new javax.swing.JButton(); + jTextFieldEmail = new javax.swing.JTextField(); + jTextFieldMobileNumber = new javax.swing.JTextField(); + jLabel5 = new javax.swing.JLabel(); + jLabelDateOfBirth = new javax.swing.JLabel(); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setPreferredSize(new java.awt.Dimension(1258, 809)); + + jLabelWelcome.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N + jLabelWelcome.setText("WELCOME TO LIBREJACK!"); + + jLabelLogin.setFont(new java.awt.Font("Dialog", 1, 36)); // NOI18N + jLabelLogin.setText("Login"); + + jLabelEmail.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + jLabelEmail.setText("Email:"); + + jLabelMobileNumber.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + jLabelMobileNumber.setText("Mobile number:"); + + jLabelUsername.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + jLabelUsername.setText("Username:"); + + jLabelPassword.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + jLabelPassword.setText("Password:"); + + jTextFieldUsername.setText("PenguinPancakes69"); + jTextFieldUsername.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextFieldUsernameActionPerformed(evt); + } + }); + + jPasswordField.setText("password123"); + jPasswordField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jPasswordFieldActionPerformed(evt); + } + }); + + jLabelPasswordRequirements.setText("Password requires at least:"); + + jLabel1.setText("- 10 characters"); + + jLabel2.setText("- 1 uppercase and lowercase letter"); + + jLabel3.setText("- 1 number"); + + jLabel4.setText("- 1 special character"); + + jButtonVerify.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N + jButtonVerify.setText("PLAY"); + jButtonVerify.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButtonVerifyActionPerformed(evt); + } + }); + + jTextFieldEmail.setText("johndoe@example.com"); + + jTextFieldMobileNumber.setText("082 738 9016"); + jTextFieldMobileNumber.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextFieldMobileNumberActionPerformed(evt); + } + }); + + jLabel5.setText("Must be a valid South African number"); + + jLabelDateOfBirth.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + jLabelDateOfBirth.setText("Date of birth:"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 947, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(335, 335, 335) + .addComponent(jLabelWelcome)) + .addGroup(layout.createSequentialGroup() + .addGap(60, 60, 60) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(jLabel3) + .addComponent(jLabel4) + .addComponent(jLabelPasswordRequirements, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel5) + .addComponent(jLabelPassword) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabelLogin) + .addComponent(jLabelUsername) + .addComponent(jLabelEmail) + .addComponent(jLabelMobileNumber) + .addComponent(jLabelDateOfBirth)) + .addGap(95, 95, 95) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jTextFieldUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE) + .addComponent(jTextFieldEmail) + .addComponent(jTextFieldMobileNumber)) + .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(329, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 664, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(33, 33, 33) + .addComponent(jLabelWelcome, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(7, 7, 7) + .addComponent(jLabelLogin) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelUsername) + .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelEmail) + .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelMobileNumber) + .addComponent(jTextFieldMobileNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabel5) + .addGap(29, 29, 29) + .addComponent(jLabelDateOfBirth) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelPassword) + .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabelPasswordRequirements) + .addGap(18, 18, 18) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel4) + .addGap(74, 74, 74) + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(68, 68, 68)) ); pack(); }// </editor-fold>//GEN-END:initComponents + private void jPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordFieldActionPerformed + + }//GEN-LAST:event_jPasswordFieldActionPerformed + + private void jButtonVerifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerifyActionPerformed + char[] passwordCh = jPasswordField.getPassword(); + String password = new String(passwordCh); // convert password to string + if (controller.areAllFieldsValid( + jTextFieldEmail.getText(), + jTextFieldMobileNumber.getText(), + password)) { + new MainGUI().setVisible(true); // open the game window + this.dispose(); // close the login screen + } + }//GEN-LAST:event_jButtonVerifyActionPerformed + + private void jTextFieldUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldUsernameActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextFieldUsernameActionPerformed + + private void jTextFieldMobileNumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMobileNumberActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextFieldMobileNumberActionPerformed + /** * @param args the command line arguments */ @@ -91,5 +252,23 @@ public class LoginGUI extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButtonVerify; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabelDateOfBirth; + private javax.swing.JLabel jLabelEmail; + private javax.swing.JLabel jLabelLogin; + private javax.swing.JLabel jLabelMobileNumber; + private javax.swing.JLabel jLabelPassword; + private javax.swing.JLabel jLabelPasswordRequirements; + private javax.swing.JLabel jLabelUsername; + private javax.swing.JLabel jLabelWelcome; + private javax.swing.JPasswordField jPasswordField; + private javax.swing.JTextField jTextFieldEmail; + private javax.swing.JTextField jTextFieldMobileNumber; + private javax.swing.JTextField jTextFieldUsername; // End of variables declaration//GEN-END:variables }