librejack

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

commit 2c468948f89649da5284f364e064288612bf1a2a
parent 1974a3e34661a4580dc6b947742e6d97a285d52f
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Sun, 12 Feb 2023 21:45:15 +0200

Add date validation

Diffstat:
Mnbproject/project.properties | 4+++-
Msrc/controller/LoginController.java | 43++++++++++++++++++++++++++++++++++++++++++-
Msrc/view/LoginGUI.form | 244++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/view/LoginGUI.java | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 306 insertions(+), 132 deletions(-)

diff --git a/nbproject/project.properties b/nbproject/project.properties @@ -31,12 +31,14 @@ dist.jar=${dist.dir}/librejack.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= +file.reference.jcalendar-1.4.jar=/home/michael/Downloads/jcalendar-1.4/lib/jcalendar-1.4.jar includes=** jar.archive.disabled=${jnlp.enabled} jar.compress=false jar.index=${jnlp.enabled} javac.classpath=\ - ${libs.absolutelayout.classpath} + ${libs.absolutelayout.classpath}:\ + ${file.reference.jcalendar-1.4.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java @@ -1,5 +1,7 @@ package controller; +import java.util.Calendar; +import java.util.Date; import java.util.regex.Pattern; import javax.swing.JOptionPane; @@ -12,10 +14,11 @@ public class LoginController { public LoginController() { } - public boolean areAllFieldsValid(String email, String mobileNumber, String password) { + public boolean areAllFieldsValid(String email, String mobileNumber, Date date, String password) { return isValidEmail(email) && isValidSouthAfricanMobileNumber(mobileNumber) && + isValidDateAndAdult(date) && isValidPassword(password); } @@ -77,6 +80,44 @@ public class LoginController { // 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 {@code true} if the date is valid and the person is at least 18 years old; {@code 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--; + } + 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: diff --git a/src/view/LoginGUI.form b/src/view/LoginGUI.form @@ -35,11 +35,129 @@ <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"/> - <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,3,54,0,0,4,-118"/> </AuxValues> - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> - <Property name="useNullLayout" type="boolean" value="false"/> + <Layout> + <DimensionLayout dim="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" attributes="0"> + <EmptySpace min="235" pref="235" max="-2" attributes="0"/> + <Component id="jLabelWelcome" 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"> + <Group type="102" 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"/> + </Group> + <EmptySpace min="-2" pref="11" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jTextFieldUsername" min="-2" pref="215" max="-2" attributes="0"/> + <Component id="jTextFieldEmail" min="-2" pref="215" max="-2" attributes="0"/> + <Component id="jTextFieldMobileNumber" min="-2" pref="215" max="-2" attributes="0"/> + <Group type="102" attributes="0"> + <Group type="103" groupAlignment="0" 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 type="102" attributes="0"> + <Component id="jButtonVerify" min="-2" pref="204" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="310" max="-2" attributes="0"/> + <Component id="jToggleButton1" min="-2" pref="221" max="-2" attributes="0"/> + </Group> + </Group> + </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="18" pref="18" max="-2" attributes="0"/> + <Component id="jLabelWelcome" min="-2" pref="105" max="-2" attributes="0"/> + <EmptySpace min="7" pref="7" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="15" pref="15" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace min="56" pref="56" 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> + <Component id="jLabelCardsImage" min="-2" pref="520" max="-2" attributes="0"/> + </Group> + </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> + <EmptySpace type="separate" pref="35" max="32767" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jToggleButton1" alignment="3" min="-2" pref="76" max="-2" attributes="0"/> + <Component id="jButtonVerify" alignment="3" min="-2" pref="86" max="-2" attributes="0"/> + </Group> + <EmptySpace min="12" pref="12" max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JLabel" name="jLabelWelcome"> @@ -49,11 +167,6 @@ </Property> <Property name="text" type="java.lang.String" value="WELCOME TO LIBREJACK!"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="235" y="33" width="-1" height="105"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelLogin"> <Properties> @@ -62,11 +175,6 @@ </Property> <Property name="text" type="java.lang.String" value="Login"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="145" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelEmail"> <Properties> @@ -75,11 +183,6 @@ </Property> <Property name="text" type="java.lang.String" value="Email:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="260" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelMobileNumber"> <Properties> @@ -88,11 +191,6 @@ </Property> <Property name="text" type="java.lang.String" value="Mobile number:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="306" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelUsername"> <Properties> @@ -101,11 +199,6 @@ </Property> <Property name="text" type="java.lang.String" value="Username:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="213" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelPassword"> <Properties> @@ -114,11 +207,6 @@ </Property> <Property name="text" type="java.lang.String" value="Password:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="442" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JTextField" name="jTextFieldUsername"> <Properties> @@ -127,11 +215,6 @@ <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextFieldUsernameActionPerformed"/> </Events> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="297" y="216" width="215" height="26"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JPasswordField" name="jPasswordField"> <Properties> @@ -140,61 +223,31 @@ <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jPasswordFieldActionPerformed"/> </Events> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="297" y="446" width="215" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelPasswordRequirements"> <Properties> <Property name="text" type="java.lang.String" value="Password requires at least:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="487" width="205" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabel1"> <Properties> <Property name="text" type="java.lang.String" value="- 10 characters"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="522" width="137" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabel2"> <Properties> <Property name="text" type="java.lang.String" value="- 1 uppercase and lowercase letter"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="551" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabel3"> <Properties> <Property name="text" type="java.lang.String" value="- 1 number"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="580" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabel4"> <Properties> <Property name="text" type="java.lang.String" value="- 1 special character"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="609" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JButton" name="jButtonVerify"> <Properties> @@ -209,21 +262,11 @@ <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonVerifyActionPerformed"/> </Events> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="700" width="204" height="86"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JTextField" name="jTextFieldEmail"> <Properties> <Property name="text" type="java.lang.String" value="john.doe@example.com"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="297" y="263" width="215" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JTextField" name="jTextFieldMobileNumber"> <Properties> @@ -232,21 +275,11 @@ <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextFieldMobileNumberActionPerformed"/> </Events> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="297" y="306" width="215" height="-1"/> - </Constraint> - </Constraints> </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> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="352" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Component class="javax.swing.JLabel" name="jLabelDateOfBirth"> <Properties> @@ -255,29 +288,14 @@ </Property> <Property name="text" type="java.lang.String" value="Date of birth:"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="60" y="398" width="-1" height="-1"/> - </Constraint> - </Constraints> </Component> <Container class="javax.swing.JPanel" name="jPanel1"> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="43" y="15" width="-1" height="-1"/> - </Constraint> - </Constraints> <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"> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="454" y="735" width="-1" height="-1"/> - </Constraint> - </Constraints> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> <Property name="useNullLayout" type="boolean" value="false"/> @@ -290,11 +308,21 @@ </Property> <Property name="text" type="java.lang.String" value="jLabel6"/> </Properties> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> - <AbsoluteConstraints x="440" y="160" width="680" height="520"/> - </Constraint> - </Constraints> + </Component> + <Component class="com.toedter.calendar.JDateChooser" name="jDateChooser1"> + </Component> + <Component class="javax.swing.JToggleButton" name="jToggleButton1"> + <Properties> + <Property name="text" type="java.lang.String" value="show date"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jToggleButton1ActionPerformed"/> + </Events> + </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 @@ -1,6 +1,8 @@ package view; import controller.LoginController; +import java.util.Date; +import javax.swing.JOptionPane; /** @@ -49,37 +51,33 @@ public class LoginGUI extends javax.swing.JFrame { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabelCardsImage = new javax.swing.JLabel(); + jDateChooser1 = new com.toedter.calendar.JDateChooser(); + jToggleButton1 = new javax.swing.JToggleButton(); + 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)); - getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabelWelcome.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N jLabelWelcome.setText("WELCOME TO LIBREJACK!"); - getContentPane().add(jLabelWelcome, new org.netbeans.lib.awtextra.AbsoluteConstraints(235, 33, -1, 105)); jLabelLogin.setFont(new java.awt.Font("Dialog", 1, 36)); // NOI18N jLabelLogin.setText("Login"); - getContentPane().add(jLabelLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 145, -1, -1)); jLabelEmail.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabelEmail.setText("Email:"); - getContentPane().add(jLabelEmail, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 260, -1, -1)); jLabelMobileNumber.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabelMobileNumber.setText("Mobile number:"); - getContentPane().add(jLabelMobileNumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 306, -1, -1)); jLabelUsername.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabelUsername.setText("Username:"); - getContentPane().add(jLabelUsername, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 213, -1, -1)); jLabelPassword.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabelPassword.setText("Password:"); - getContentPane().add(jLabelPassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 442, -1, -1)); jTextFieldUsername.setText("PenguinPancakes69"); jTextFieldUsername.addActionListener(new java.awt.event.ActionListener() { @@ -87,7 +85,6 @@ public class LoginGUI extends javax.swing.JFrame { jTextFieldUsernameActionPerformed(evt); } }); - getContentPane().add(jTextFieldUsername, new org.netbeans.lib.awtextra.AbsoluteConstraints(297, 216, 215, 26)); jPasswordField.setText("password123"); jPasswordField.addActionListener(new java.awt.event.ActionListener() { @@ -95,22 +92,16 @@ public class LoginGUI extends javax.swing.JFrame { jPasswordFieldActionPerformed(evt); } }); - getContentPane().add(jPasswordField, new org.netbeans.lib.awtextra.AbsoluteConstraints(297, 446, 215, -1)); jLabelPasswordRequirements.setText("Password requires at least:"); - getContentPane().add(jLabelPasswordRequirements, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 487, 205, -1)); jLabel1.setText("- 10 characters"); - getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 522, 137, -1)); jLabel2.setText("- 1 uppercase and lowercase letter"); - getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 551, -1, -1)); jLabel3.setText("- 1 number"); - getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 580, -1, -1)); jLabel4.setText("- 1 special character"); - getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 609, -1, -1)); jButtonVerify.setBackground(new java.awt.Color(204, 204, 204)); jButtonVerify.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N @@ -120,10 +111,8 @@ public class LoginGUI extends javax.swing.JFrame { jButtonVerifyActionPerformed(evt); } }); - getContentPane().add(jButtonVerify, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 700, 204, 86)); jTextFieldEmail.setText("john.doe@example.com"); - getContentPane().add(jTextFieldEmail, new org.netbeans.lib.awtextra.AbsoluteConstraints(297, 263, 215, -1)); jTextFieldMobileNumber.setText("082 738 9016"); jTextFieldMobileNumber.addActionListener(new java.awt.event.ActionListener() { @@ -131,24 +120,129 @@ public class LoginGUI extends javax.swing.JFrame { jTextFieldMobileNumberActionPerformed(evt); } }); - getContentPane().add(jTextFieldMobileNumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(297, 306, 215, -1)); jLabel5.setText("Must be a valid South African number"); - getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 352, -1, -1)); jLabelDateOfBirth.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabelDateOfBirth.setText("Date of birth:"); - getContentPane().add(jLabelDateOfBirth, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 398, -1, -1)); jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); - getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(43, 15, -1, -1)); jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); - getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(454, 735, -1, -1)); jLabelCardsImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/cards_icon.png"))); // NOI18N jLabelCardsImage.setText("jLabel6"); - getContentPane().add(jLabelCardsImage, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 160, 680, 520)); + + jToggleButton1.setText("show date"); + jToggleButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jToggleButton1ActionPerformed(evt); + } + }); + + 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() + .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(235, 235, 235) + .addComponent(jLabelWelcome)) + .addGroup(layout.createSequentialGroup() + .addGap(60, 60, 60) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .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)) + .addGap(11, 11, 11) + .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) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .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)))) + .addGroup(layout.createSequentialGroup() + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(310, 310, 310) + .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))) + ); + 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(18, 18, 18) + .addComponent(jLabelWelcome, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(7, 7, 7) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(15, 15, 15) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(56, 56, 56) + .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)) + .addComponent(jLabelCardsImage, javax.swing.GroupLayout.PREFERRED_SIZE, 520, 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))))) + .addGap(18, 35, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButtonVerify, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(12, 12, 12)) + ); pack(); }// </editor-fold>//GEN-END:initComponents @@ -160,9 +254,11 @@ public class LoginGUI extends javax.swing.JFrame { 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 @@ -177,6 +273,10 @@ public class LoginGUI extends javax.swing.JFrame { // TODO add your handling code here: }//GEN-LAST:event_jTextFieldMobileNumberActionPerformed + private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed + JOptionPane.showMessageDialog(null, jDateChooser1.getDate()); + }//GEN-LAST:event_jToggleButton1ActionPerformed + /** * @param args the command line arguments */ @@ -212,11 +312,13 @@ public class LoginGUI extends javax.swing.JFrame { // 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; @@ -233,5 +335,6 @@ public class LoginGUI extends javax.swing.JFrame { private javax.swing.JTextField jTextFieldEmail; private javax.swing.JTextField jTextFieldMobileNumber; private javax.swing.JTextField jTextFieldUsername; + private javax.swing.JToggleButton jToggleButton1; // End of variables declaration//GEN-END:variables }