librejack

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

commit ee6d4d6697be9a22a93048ca5d36ebb7aba381cb
parent 0368ce9cdc35f1c8dea7db2589d4f92b57e5f5e0
Author: Michael Neuper <michael@michaelneuper.com>
Date:   Sat, 29 Apr 2023 21:40:32 +0200

Add functionality for play button

Diffstat:
Msrc/view/Login.form | 17++++++++++-------
Msrc/view/Login.java | 72+++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
2 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/src/view/Login.form b/src/view/Login.form @@ -161,7 +161,7 @@ <Component id="jTextFieldUsername" alignment="0" max="32767" attributes="0"/> <Component id="jTextFieldEmail" alignment="0" pref="183" max="32767" attributes="0"/> <Component id="jTextFieldMobileNumber" alignment="0" max="32767" attributes="0"/> - <Component id="jPasswordField1" max="32767" attributes="0"/> + <Component id="jPasswordField" max="32767" attributes="0"/> <Component id="jSeparator2" alignment="0" pref="183" max="32767" attributes="0"/> <Component id="jSeparator3" alignment="0" pref="183" max="32767" attributes="0"/> <Component id="jDateChooser1" alignment="1" max="32767" attributes="0"/> @@ -207,7 +207,7 @@ </Group> <Group type="102" alignment="0" attributes="0"> <EmptySpace type="separate" max="-2" attributes="0"/> - <Component id="jPasswordField1" min="-2" max="-2" attributes="0"/> + <Component id="jPasswordField" min="-2" max="-2" attributes="0"/> </Group> </Group> <EmptySpace max="-2" attributes="0"/> @@ -345,7 +345,7 @@ </Property> </Properties> </Component> - <Component class="javax.swing.JPasswordField" name="jPasswordField1"> + <Component class="javax.swing.JPasswordField" name="jPasswordField"> <Properties> <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <Color blue="0" green="66" red="0" type="rgb"/> @@ -361,6 +361,9 @@ <Border info="null"/> </Property> </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jPasswordFieldActionPerformed"/> + </Events> </Component> <Component class="javax.swing.JSeparator" name="jSeparator1"> <Properties> @@ -434,7 +437,7 @@ </Group> <Group type="102" alignment="0" attributes="0"> <EmptySpace min="-2" pref="145" max="-2" attributes="0"/> - <Component id="jButton1" min="-2" pref="98" max="-2" attributes="0"/> + <Component id="jButtonPlay" min="-2" pref="98" max="-2" attributes="0"/> </Group> </Group> <EmptySpace pref="220" max="32767" attributes="0"/> @@ -447,7 +450,7 @@ <EmptySpace pref="53" max="32767" attributes="0"/> <Component id="jLabel1" min="-2" pref="264" max="-2" attributes="0"/> <EmptySpace min="-2" pref="34" max="-2" attributes="0"/> - <Component id="jButton1" min="-2" pref="50" max="-2" attributes="0"/> + <Component id="jButtonPlay" min="-2" pref="50" max="-2" attributes="0"/> <EmptySpace min="-2" pref="29" max="-2" attributes="0"/> </Group> </Group> @@ -461,7 +464,7 @@ </Property> </Properties> </Component> - <Component class="javax.swing.JButton" name="jButton1"> + <Component class="javax.swing.JButton" name="jButtonPlay"> <Properties> <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <Color blue="0" green="66" red="0" type="rgb"/> @@ -478,7 +481,7 @@ </Property> </Properties> <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonPlayActionPerformed"/> </Events> </Component> </SubComponents> diff --git a/src/view/Login.java b/src/view/Login.java @@ -1,8 +1,13 @@ package view; +import controller.LoginController; +import java.util.Date; + /** + * GUI for login screen. * - * @author michael + * @author Michael Neuper + * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a> */ public class Login extends javax.swing.JFrame { @@ -13,6 +18,8 @@ public class Login extends javax.swing.JFrame { 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 @@ -36,7 +43,7 @@ public class Login extends javax.swing.JFrame { jTextFieldUsername = new javax.swing.JTextField(); jTextFieldEmail = new javax.swing.JTextField(); jTextFieldMobileNumber = new javax.swing.JTextField(); - jPasswordField1 = new javax.swing.JPasswordField(); + jPasswordField = new javax.swing.JPasswordField(); jSeparator1 = new javax.swing.JSeparator(); jSeparator2 = new javax.swing.JSeparator(); jSeparator3 = new javax.swing.JSeparator(); @@ -44,7 +51,7 @@ public class Login extends javax.swing.JFrame { jDateChooser1 = new com.toedter.calendar.JDateChooser(); jPanelCenter = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); + jButtonPlay = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(0, 153, 0)); @@ -156,11 +163,16 @@ public class Login extends javax.swing.JFrame { jTextFieldMobileNumber.setText("082 738 9016"); jTextFieldMobileNumber.setBorder(null); - jPasswordField1.setBackground(new java.awt.Color(0, 102, 0)); - jPasswordField1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N - jPasswordField1.setForeground(new java.awt.Color(153, 153, 153)); - jPasswordField1.setText("Password@12345"); - jPasswordField1.setBorder(null); + jPasswordField.setBackground(new java.awt.Color(0, 102, 0)); + jPasswordField.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N + jPasswordField.setForeground(new java.awt.Color(153, 153, 153)); + jPasswordField.setText("Password@12345"); + jPasswordField.setBorder(null); + jPasswordField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jPasswordFieldActionPerformed(evt); + } + }); jSeparator1.setBackground(new java.awt.Color(204, 204, 204)); @@ -193,7 +205,7 @@ public class Login extends javax.swing.JFrame { .addComponent(jTextFieldUsername) .addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) .addComponent(jTextFieldMobileNumber) - .addComponent(jPasswordField1) + .addComponent(jPasswordField) .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) .addComponent(jDateChooser1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -231,7 +243,7 @@ public class Login extends javax.swing.JFrame { .addComponent(jLabelPassword)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(18, 18, 18) - .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(52, Short.MAX_VALUE)) @@ -246,14 +258,14 @@ public class Login extends javax.swing.JFrame { jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/cards_resized.png"))); // NOI18N - jButton1.setBackground(new java.awt.Color(0, 102, 0)); - jButton1.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N - jButton1.setForeground(new java.awt.Color(204, 204, 204)); - jButton1.setText("PLAY"); - jButton1.setBorder(null); - jButton1.addActionListener(new java.awt.event.ActionListener() { + jButtonPlay.setBackground(new java.awt.Color(0, 102, 0)); + jButtonPlay.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N + jButtonPlay.setForeground(new java.awt.Color(204, 204, 204)); + jButtonPlay.setText("PLAY"); + jButtonPlay.setBorder(null); + jButtonPlay.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); + jButtonPlayActionPerformed(evt); } }); @@ -268,7 +280,7 @@ public class Login extends javax.swing.JFrame { .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanelCenterLayout.createSequentialGroup() .addGap(145, 145, 145) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jButtonPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(220, Short.MAX_VALUE)) ); jPanelCenterLayout.setVerticalGroup( @@ -277,7 +289,7 @@ public class Login extends javax.swing.JFrame { .addContainerGap(53, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(34, 34, 34) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButtonPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29)) ); @@ -290,9 +302,23 @@ public class Login extends javax.swing.JFrame { // TODO add your handling code here: }//GEN-LAST:event_jTextFieldEmailActionPerformed - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + private void jButtonPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPlayActionPerformed + 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_jButtonPlayActionPerformed + + private void jPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordFieldActionPerformed // TODO add your handling code here: - }//GEN-LAST:event_jButton1ActionPerformed + }//GEN-LAST:event_jPasswordFieldActionPerformed /** * @param args the command line arguments @@ -330,7 +356,7 @@ public class Login extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; + private javax.swing.JButton jButtonPlay; private com.toedter.calendar.JDateChooser jDateChooser1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabelDateOfBirth; @@ -345,7 +371,7 @@ public class Login extends javax.swing.JFrame { private javax.swing.JPanel jPanelLoginText; private javax.swing.JPanel jPanelWelcomeText; private javax.swing.JPanel jPanelWest; - private javax.swing.JPasswordField jPasswordField1; + private javax.swing.JPasswordField jPasswordField; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3;