librejack

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

commit f80112f47687d2c112979361b62d0149b5c6b252
parent 19781dfd62c2de80fcf81f409744a5958d43c8fd
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Thu, 27 Apr 2023 12:30:06 +0200

Add login

Diffstat:
Dassets/background.jpg | 0
Asrc/controller/LoginController.java | 205+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/view/LoginGUI.form | 313+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/view/LoginGUI.java | 320+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 838 insertions(+), 0 deletions(-)

diff --git a/assets/background.jpg b/assets/background.jpg Binary files differ. diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java @@ -0,0 +1,205 @@ +package controller; + +import java.util.Calendar; +import java.util.Date; +import java.util.regex.Pattern; +import javax.swing.JOptionPane; + +/** + * + * @author Michael + */ +public class LoginController { + + public LoginController() { + } + + /** + * Checks whether all the entered fields are present and valid + * + * @param email + * @param mobileNumber + * @param date + * @param password + * @return true if all fields are valid, false otherwise + */ + public boolean areAllFieldsValid(String email, String mobileNumber, Date date, String password) { + return isValidEmail(email) + && isValidSouthAfricanMobileNumber(mobileNumber) + && isValidDateAndAdult(date) + && 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) { + // Check if email is null + if (email == null) { + JOptionPane.showMessageDialog(null, "Please enter an email"); + } + + // Define regular expression pattern for valid email addresses + String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + + "[a-zA-Z0-9_+&*-]+)*@" + + "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; + Pattern pattern = Pattern.compile(emailRegex); + + // Check if email matches the pattern + boolean isValid = pattern.matcher(email).matches(); + + // If email is not valid, show error message + if (!isValid) { + JOptionPane.showMessageDialog(null, "Please enter a valid email"); + } + + // Return whether email is valid + 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 if a given date is valid and the person is at least 18 years old. + * + * @param date the date to be checked + * @return true if the date is valid and the person is at least 18 years + * old, false otherwise + */ + private static boolean isValidDateAndAdult(Date date) { + // Check if the date is null + if (date == null) { + JOptionPane.showMessageDialog(null, "Please enter a date of birth"); + return false; + } + + // Check if the date is in the past + if (date.after(new Date())) { + JOptionPane.showMessageDialog(null, "You were not born in the future!"); + return false; + } + + // Check if the person is at least 18 years old + Calendar dob = Calendar.getInstance(); + dob.setTime(date); + Calendar now = Calendar.getInstance(); + now.setTime(new Date()); + int age = now.get(Calendar.YEAR) - dob.get(Calendar.YEAR); + if (now.get(Calendar.MONTH) < dob.get(Calendar.MONTH) + || (now.get(Calendar.MONTH) == dob.get(Calendar.MONTH) && now.get(Calendar.DAY_OF_MONTH) < dob.get(Calendar.DAY_OF_MONTH))) { + age--; + } else { + } + if (age < 18) { + JOptionPane.showMessageDialog(null, "You need to be at least 18 years old to gamble!"); + return false; + } + + // If all checks pass, the date is valid and the person is at least 18 + 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 true if password is valid, false otherwise + */ + private boolean isValidPassword(String password) { + boolean hasUpperCase = false; + boolean hasLowerCase = false; + boolean hasNumber = false; + boolean hasSpecialChar = false; + + if (password == null || password.length() < 10) { + JOptionPane.showMessageDialog(null, "Password must be at least 10 characters long"); + return false; + } + + for (int i = 0; i < password.length(); i++) { + char ch = password.charAt(i); + + if (Character.isUpperCase(ch)) { + hasUpperCase = true; + } else if (Character.isLowerCase(ch)) { + hasLowerCase = true; + } else if (Character.isDigit(ch)) { + hasNumber = true; + } else if (isSpecialCharacter(ch)) { + hasSpecialChar = true; + } + } + + 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; + } + + /** + * Checks whether a character is a special character, i.e., one of the + * following: !@#$%^&*()-+=[]{}|\;:'",<.>/?. + * + * @param ch the character to check + * @return true if the character is a special character, false otherwise + */ + private boolean isSpecialCharacter(char ch) { + String specialCharacters = "!@#$%^&*()-+=[]{}|\\;:'\",<.>/?"; + return specialCharacters.contains(String.valueOf(ch)); + } + +} diff --git a/src/view/LoginGUI.form b/src/view/LoginGUI.form @@ -0,0 +1,313 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <NonVisualComponents> + <Container class="javax.swing.JPanel" name="jPanel3"> + <Properties> + <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="0" green="cc" red="33" type="rgb"/> + </Property> + </Properties> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/> + </Container> + </NonVisualComponents> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="99" green="99" red="99" type="rgb"/> + </Property> + <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[829, 786]"/> + </Property> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + <SyntheticProperty name="generateCenter" type="boolean" value="false"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + </AuxValues> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="43" pref="43" max="-2" attributes="0"/> + <Component id="jPanel1" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="60" pref="60" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabelLogin" min="-2" max="-2" attributes="0"/> + <Component id="jLabelUsername" min="-2" max="-2" attributes="0"/> + <Component id="jLabelEmail" min="-2" max="-2" attributes="0"/> + <Component id="jLabelMobileNumber" min="-2" max="-2" attributes="0"/> + <Component id="jLabel5" min="-2" max="-2" attributes="0"/> + <Component id="jLabelDateOfBirth" min="-2" max="-2" attributes="0"/> + <Component id="jLabelPassword" min="-2" max="-2" attributes="0"/> + <Component id="jLabelPasswordRequirements" min="-2" pref="205" max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" pref="137" max="-2" attributes="0"/> + <Component id="jLabel2" min="-2" max="-2" attributes="0"/> + <Component id="jLabel3" min="-2" max="-2" attributes="0"/> + <Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabel6" min="-2" max="-2" attributes="0"/> + <Component id="jButtonVerify" alignment="0" min="-2" pref="204" max="-2" attributes="0"/> + </Group> + <EmptySpace min="-2" pref="11" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabelWelcome" alignment="0" min="-2" max="-2" attributes="0"/> + <Group type="102" alignment="0" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jTextFieldUsername" alignment="0" min="-2" pref="215" max="-2" attributes="0"/> + <Component id="jTextFieldEmail" alignment="0" min="-2" pref="215" max="-2" attributes="0"/> + <Component id="jTextFieldMobileNumber" alignment="0" min="-2" pref="215" max="-2" attributes="0"/> + <Component id="jDateChooser1" min="-2" pref="210" max="-2" attributes="0"/> + <Component id="jPasswordField" min="-2" pref="215" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + <Component id="jLabelCardsImage" min="-2" pref="680" max="-2" attributes="0"/> + </Group> + </Group> + </Group> + </Group> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="15" pref="15" max="-2" attributes="0"/> + <Component id="jPanel1" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="8" max="-2" attributes="0"/> + <Component id="jLabelWelcome" min="-2" pref="105" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="-2" pref="17" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="-2" pref="71" max="-2" attributes="0"/> + <Component id="jTextFieldUsername" min="-2" pref="26" max="-2" attributes="0"/> + <EmptySpace min="21" pref="21" max="-2" attributes="0"/> + <Component id="jTextFieldEmail" min="-2" max="-2" attributes="0"/> + <EmptySpace min="18" pref="18" max="-2" attributes="0"/> + <Component id="jTextFieldMobileNumber" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="68" max="-2" attributes="0"/> + <Component id="jDateChooser1" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <Component id="jLabelLogin" min="-2" max="-2" attributes="0"/> + <EmptySpace min="18" pref="18" max="-2" attributes="0"/> + <Component id="jLabelUsername" min="-2" max="-2" attributes="0"/> + <EmptySpace min="21" pref="21" max="-2" attributes="0"/> + <Component id="jLabelEmail" min="-2" max="-2" attributes="0"/> + <EmptySpace min="20" pref="20" max="-2" attributes="0"/> + <Component id="jLabelMobileNumber" min="-2" max="-2" attributes="0"/> + <EmptySpace min="20" pref="20" max="-2" attributes="0"/> + <Component id="jLabel5" min="-2" max="-2" attributes="0"/> + <EmptySpace min="29" pref="29" max="-2" attributes="0"/> + <Component id="jLabelDateOfBirth" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="13" max="-2" attributes="0"/> + <Component id="jLabel6" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jPasswordField" min="-2" max="-2" attributes="0"/> + <Group type="102" attributes="0"> + <Component id="jLabelPassword" min="-2" max="-2" attributes="0"/> + <EmptySpace type="unrelated" 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="separate" max="-2" attributes="0"/> + <Component id="jLabel2" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jLabel3" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jLabel4" min="-2" max="-2" attributes="0"/> + </Group> + </Group> + </Group> + </Group> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="35" max="-2" attributes="0"/> + <Component id="jLabelCardsImage" min="-2" pref="520" max="-2" attributes="0"/> + </Group> + </Group> + <EmptySpace min="-2" pref="25" max="-2" attributes="0"/> + <Component id="jButtonVerify" min="-2" pref="86" max="-2" attributes="0"/> + <EmptySpace pref="46" max="32767" 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="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="cc" green="cc" red="cc" type="rgb"/> + </Property> + <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="john.doe@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> + <Container class="javax.swing.JPanel" name="jPanel1"> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> + <Property name="useNullLayout" type="boolean" value="false"/> + </Layout> + </Container> + <Container class="javax.swing.JPanel" name="jPanel2"> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> + <Property name="useNullLayout" type="boolean" value="false"/> + </Layout> + </Container> + <Component class="javax.swing.JLabel" name="jLabelCardsImage"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="3" name="/assets/cards_icon.png"/> + </Property> + <Property name="text" type="java.lang.String" value="jLabel6"/> + </Properties> + </Component> + <Component class="com.toedter.calendar.JDateChooser" name="jDateChooser1"> + </Component> + <Component class="javax.swing.JLabel" name="jLabel6"> + <Properties> + <Property name="text" type="java.lang.String" value="You need to be at least 18 to gamble"/> + </Properties> + </Component> + </SubComponents> +</Form> diff --git a/src/view/LoginGUI.java b/src/view/LoginGUI.java @@ -0,0 +1,320 @@ +package view; + +import controller.LoginController; +import java.util.Date; + +/** + * + * @author Michael + */ +public class LoginGUI extends javax.swing.JFrame { + + /** + * Creates new form LoginGUI + */ + public LoginGUI() { + initComponents(); + } + + LoginController controller = new LoginController(); + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jPanel3 = new javax.swing.JPanel(); + 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(); + jPanel1 = new javax.swing.JPanel(); + jPanel2 = new javax.swing.JPanel(); + jLabelCardsImage = new javax.swing.JLabel(); + jDateChooser1 = new com.toedter.calendar.JDateChooser(); + jLabel6 = new javax.swing.JLabel(); + + jPanel3.setBackground(new java.awt.Color(51, 204, 0)); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setBackground(new java.awt.Color(153, 153, 153)); + setMinimumSize(new java.awt.Dimension(829, 786)); + + 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.setBackground(new java.awt.Color(204, 204, 204)); + 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("john.doe@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:"); + + jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); + + jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); + + jLabelCardsImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/cards_icon.png"))); // NOI18N + jLabelCardsImage.setText("jLabel6"); + + jLabel6.setText("You need to be at least 18 to gamble"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(43, 43, 43) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(60, 60, 60) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabelLogin) + .addComponent(jLabelUsername) + .addComponent(jLabelEmail) + .addComponent(jLabelMobileNumber) + .addComponent(jLabel5) + .addComponent(jLabelDateOfBirth) + .addComponent(jLabelPassword) + .addComponent(jLabelPasswordRequirements, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(jLabel3) + .addComponent(jLabel4) + .addComponent(jLabel6) + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(11, 11, 11) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabelWelcome) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jTextFieldMobileNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabelCardsImage, javax.swing.GroupLayout.PREFERRED_SIZE, 680, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(15, 15, 15) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(8, 8, 8) + .addComponent(jLabelWelcome, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(17, 17, 17) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(71, 71, 71) + .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(21, 21, 21) + .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jTextFieldMobileNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(68, 68, 68) + .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabelLogin) + .addGap(18, 18, 18) + .addComponent(jLabelUsername) + .addGap(21, 21, 21) + .addComponent(jLabelEmail) + .addGap(20, 20, 20) + .addComponent(jLabelMobileNumber) + .addGap(20, 20, 20) + .addComponent(jLabel5) + .addGap(29, 29, 29) + .addComponent(jLabelDateOfBirth) + .addGap(13, 13, 13) + .addComponent(jLabel6) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabelPassword) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabelPasswordRequirements) + .addGap(18, 18, 18) + .addComponent(jLabel1) + .addGap(18, 18, 18) + .addComponent(jLabel2) + .addGap(18, 18, 18) + .addComponent(jLabel3) + .addGap(18, 18, 18) + .addComponent(jLabel4)))))) + .addGroup(layout.createSequentialGroup() + .addGap(35, 35, 35) + .addComponent(jLabelCardsImage, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(25, 25, 25) + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(46, Short.MAX_VALUE)) + ); + + 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 + Date selectedDate = jDateChooser1.getDate(); + if (controller.areAllFieldsValid( + jTextFieldEmail.getText(), + jTextFieldMobileNumber.getText(), + selectedDate, + 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 + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(LoginGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(LoginGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(LoginGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(LoginGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(() -> { + new LoginGUI().setVisible(true); + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButtonVerify; + private com.toedter.calendar.JDateChooser jDateChooser1; + 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 jLabel6; + private javax.swing.JLabel jLabelCardsImage; + 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.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel jPanel3; + 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 +}