4 * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 package uk.ac.ntu.n0521366.wsyd.client;
26 import javax.swing.JFrame;
29 * @author Eddie Berrisford-Lynch
31 public class Login extends javax.swing.JDialog {
34 * Creates new form WSYD_Login
36 public Login(java.awt.Frame parent, boolean modal) {
39 this.getRootPane().setDefaultButton(gButtonLogin);
42 public void setUserName(String newName) {
44 gFieldName.setText(newName);
47 * This method is called from within the constructor to initialize the form.
48 * WARNING: Do NOT modify this code. The content of this method is always
49 * regenerated by the Form Editor.
51 @SuppressWarnings("unchecked")
52 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
53 private void initComponents() {
54 java.awt.GridBagConstraints gridBagConstraints;
56 gLabelWSYD = new javax.swing.JLabel();
57 gLabelName = new javax.swing.JLabel();
58 gFieldName = new javax.swing.JTextField();
59 gLabelPassword = new javax.swing.JLabel();
60 gFieldPassword = new javax.swing.JPasswordField();
61 gButtonLogin = new javax.swing.JButton();
62 gButtonRegister = new javax.swing.JButton();
63 gLabelRegister = new javax.swing.JLabel();
65 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
66 setMinimumSize(new java.awt.Dimension(400, 300));
67 addWindowListener(new java.awt.event.WindowAdapter() {
68 public void windowClosing(java.awt.event.WindowEvent evt) {
69 formWindowClosing(evt);
71 public void windowClosed(java.awt.event.WindowEvent evt) {
72 formWindowClosed(evt);
75 java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
76 layout.columnWidths = new int[] {0, 5, 0};
77 layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0};
78 getContentPane().setLayout(layout);
80 gLabelWSYD.setText("Welcome to We Stealz Your Dataz!");
81 gridBagConstraints = new java.awt.GridBagConstraints();
82 gridBagConstraints.gridx = 0;
83 gridBagConstraints.gridy = 0;
84 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
85 gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
86 getContentPane().add(gLabelWSYD, gridBagConstraints);
88 gLabelName.setText("Name:");
89 gridBagConstraints = new java.awt.GridBagConstraints();
90 gridBagConstraints.gridx = 0;
91 gridBagConstraints.gridy = 2;
92 getContentPane().add(gLabelName, gridBagConstraints);
94 gFieldName.setText("Enter Username...");
95 gFieldName.setMinimumSize(new java.awt.Dimension(70, 25));
96 gFieldName.setPreferredSize(new java.awt.Dimension(150, 25));
97 gFieldName.addActionListener(new java.awt.event.ActionListener() {
98 public void actionPerformed(java.awt.event.ActionEvent evt) {
99 gFieldNameActionPerformed(evt);
102 gridBagConstraints = new java.awt.GridBagConstraints();
103 gridBagConstraints.gridx = 2;
104 gridBagConstraints.gridy = 2;
105 getContentPane().add(gFieldName, gridBagConstraints);
107 gLabelPassword.setText("Password:");
108 gridBagConstraints = new java.awt.GridBagConstraints();
109 gridBagConstraints.gridx = 0;
110 gridBagConstraints.gridy = 4;
111 getContentPane().add(gLabelPassword, gridBagConstraints);
113 gFieldPassword.setMinimumSize(new java.awt.Dimension(70, 19));
114 gFieldPassword.setPreferredSize(new java.awt.Dimension(150, 25));
115 gFieldPassword.addActionListener(new java.awt.event.ActionListener() {
116 public void actionPerformed(java.awt.event.ActionEvent evt) {
117 gFieldPasswordActionPerformed(evt);
120 gridBagConstraints = new java.awt.GridBagConstraints();
121 gridBagConstraints.gridx = 2;
122 gridBagConstraints.gridy = 4;
123 getContentPane().add(gFieldPassword, gridBagConstraints);
125 gButtonLogin.setText("Login");
126 gButtonLogin.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
127 gButtonLogin.addMouseListener(new java.awt.event.MouseAdapter() {
128 public void mouseClicked(java.awt.event.MouseEvent evt) {
129 gButtonLoginMouseClicked(evt);
132 gButtonLogin.addActionListener(new java.awt.event.ActionListener() {
133 public void actionPerformed(java.awt.event.ActionEvent evt) {
134 gButtonLoginActionPerformed(evt);
137 gridBagConstraints = new java.awt.GridBagConstraints();
138 gridBagConstraints.gridx = 2;
139 gridBagConstraints.gridy = 6;
140 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
141 gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
142 getContentPane().add(gButtonLogin, gridBagConstraints);
144 gButtonRegister.setText("Register");
145 gButtonRegister.addMouseListener(new java.awt.event.MouseAdapter() {
146 public void mouseClicked(java.awt.event.MouseEvent evt) {
147 gButtonRegisterMouseClicked(evt);
150 gridBagConstraints = new java.awt.GridBagConstraints();
151 gridBagConstraints.gridx = 2;
152 gridBagConstraints.gridy = 8;
153 gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
154 getContentPane().add(gButtonRegister, gridBagConstraints);
156 gLabelRegister.setText("Not already registered?");
157 gridBagConstraints = new java.awt.GridBagConstraints();
158 gridBagConstraints.gridx = 0;
159 gridBagConstraints.gridy = 8;
160 gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
161 getContentPane().add(gLabelRegister, gridBagConstraints);
164 }// </editor-fold>//GEN-END:initComponents
166 private void gFieldNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldNameActionPerformed
167 // TODO add your handling code here:
168 }//GEN-LAST:event_gFieldNameActionPerformed
170 private void gButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gButtonLoginActionPerformed
171 // TODO add your handling code here:
172 }//GEN-LAST:event_gButtonLoginActionPerformed
174 private void gFieldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldPasswordActionPerformed
175 // TODO add your handling code here:
176 }//GEN-LAST:event_gFieldPasswordActionPerformed
179 * Send the Username Password pair to the server to be validated.
183 private void gButtonLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonLoginMouseClicked
184 // TODO add your handling code here:
185 ((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()));
186 }//GEN-LAST:event_gButtonLoginMouseClicked
188 private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
189 // TODO add your handling code here:
190 }//GEN-LAST:event_formWindowClosed
192 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
193 // TODO add your handling code here:
194 ((ClientGUI)this.getOwner()).loginAbort();
195 }//GEN-LAST:event_formWindowClosing
197 private void gButtonRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonRegisterMouseClicked
198 // TODO add your handling code here:
199 ((ClientGUI)this.getOwner()).registrationProfileDialog();
200 }//GEN-LAST:event_gButtonRegisterMouseClicked
203 * @param args the command line arguments
205 public static void main(String args[]) {
206 /* Set the Nimbus look and feel */
207 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
208 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
209 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
212 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
213 if ("Nimbus".equals(info.getName())) {
214 javax.swing.UIManager.setLookAndFeel(info.getClassName());
218 } catch (ClassNotFoundException ex) {
219 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
220 } catch (InstantiationException ex) {
221 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
222 } catch (IllegalAccessException ex) {
223 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
224 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
225 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
230 /* Create and display the dialog */
231 java.awt.EventQueue.invokeLater(new Runnable() {
233 Login dialog = new Login(new javax.swing.JFrame(), true);
234 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
236 public void windowClosing(java.awt.event.WindowEvent e) {
240 dialog.setVisible(true);
245 // Variables declaration - do not modify//GEN-BEGIN:variables
246 private javax.swing.JButton gButtonLogin;
247 private javax.swing.JButton gButtonRegister;
248 private javax.swing.JTextField gFieldName;
249 private javax.swing.JPasswordField gFieldPassword;
250 private javax.swing.JLabel gLabelName;
251 private javax.swing.JLabel gLabelPassword;
252 private javax.swing.JLabel gLabelRegister;
253 private javax.swing.JLabel gLabelWSYD;
254 // End of variables declaration//GEN-END:variables