2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
6 package uk.ac.ntu.n0521366.wsyd.client;
8 import javax.swing.JFrame;
11 * @author Eddie Berrisford-Lynch
13 public class Login extends javax.swing.JDialog {
16 * Creates new form WSYD_Login
18 public Login(java.awt.Frame parent, boolean modal) {
24 * This method is called from within the constructor to initialize the form.
25 * WARNING: Do NOT modify this code. The content of this method is always
26 * regenerated by the Form Editor.
28 @SuppressWarnings("unchecked")
29 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
30 private void initComponents() {
31 java.awt.GridBagConstraints gridBagConstraints;
33 gLabelWSYD = new javax.swing.JLabel();
34 gLabelName = new javax.swing.JLabel();
35 gFieldName = new javax.swing.JTextField();
36 gLabelPassword = new javax.swing.JLabel();
37 gFieldPassword = new javax.swing.JPasswordField();
38 gButtonLogin = new javax.swing.JButton();
39 gButtonRegister = new javax.swing.JButton();
40 gLabelRegister = new javax.swing.JLabel();
42 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
43 setMinimumSize(new java.awt.Dimension(400, 300));
44 addWindowListener(new java.awt.event.WindowAdapter() {
45 public void windowClosing(java.awt.event.WindowEvent evt) {
46 formWindowClosing(evt);
48 public void windowClosed(java.awt.event.WindowEvent evt) {
49 formWindowClosed(evt);
52 java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
53 layout.columnWidths = new int[] {0, 5, 0};
54 layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0};
55 getContentPane().setLayout(layout);
57 gLabelWSYD.setText("Welcome to We Stealz Your Dataz!");
58 gridBagConstraints = new java.awt.GridBagConstraints();
59 gridBagConstraints.gridx = 0;
60 gridBagConstraints.gridy = 0;
61 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
62 gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
63 getContentPane().add(gLabelWSYD, gridBagConstraints);
65 gLabelName.setText("Name:");
66 gridBagConstraints = new java.awt.GridBagConstraints();
67 gridBagConstraints.gridx = 0;
68 gridBagConstraints.gridy = 2;
69 getContentPane().add(gLabelName, gridBagConstraints);
71 gFieldName.setText("Enter Username...");
72 gFieldName.setMinimumSize(new java.awt.Dimension(70, 25));
73 gFieldName.setPreferredSize(new java.awt.Dimension(150, 25));
74 gFieldName.addActionListener(new java.awt.event.ActionListener() {
75 public void actionPerformed(java.awt.event.ActionEvent evt) {
76 gFieldNameActionPerformed(evt);
79 gridBagConstraints = new java.awt.GridBagConstraints();
80 gridBagConstraints.gridx = 2;
81 gridBagConstraints.gridy = 2;
82 getContentPane().add(gFieldName, gridBagConstraints);
84 gLabelPassword.setText("Password:");
85 gridBagConstraints = new java.awt.GridBagConstraints();
86 gridBagConstraints.gridx = 0;
87 gridBagConstraints.gridy = 4;
88 getContentPane().add(gLabelPassword, gridBagConstraints);
90 gFieldPassword.setMinimumSize(new java.awt.Dimension(70, 19));
91 gFieldPassword.setPreferredSize(new java.awt.Dimension(150, 25));
92 gFieldPassword.addActionListener(new java.awt.event.ActionListener() {
93 public void actionPerformed(java.awt.event.ActionEvent evt) {
94 gFieldPasswordActionPerformed(evt);
97 gridBagConstraints = new java.awt.GridBagConstraints();
98 gridBagConstraints.gridx = 2;
99 gridBagConstraints.gridy = 4;
100 getContentPane().add(gFieldPassword, gridBagConstraints);
102 gButtonLogin.setText("Login");
103 gButtonLogin.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
104 gButtonLogin.addMouseListener(new java.awt.event.MouseAdapter() {
105 public void mouseClicked(java.awt.event.MouseEvent evt) {
106 gButtonLoginMouseClicked(evt);
109 gButtonLogin.addActionListener(new java.awt.event.ActionListener() {
110 public void actionPerformed(java.awt.event.ActionEvent evt) {
111 gButtonLoginActionPerformed(evt);
114 gridBagConstraints = new java.awt.GridBagConstraints();
115 gridBagConstraints.gridx = 2;
116 gridBagConstraints.gridy = 6;
117 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
118 gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
119 getContentPane().add(gButtonLogin, gridBagConstraints);
121 gButtonRegister.setText("Register");
122 gButtonRegister.addMouseListener(new java.awt.event.MouseAdapter() {
123 public void mouseClicked(java.awt.event.MouseEvent evt) {
124 gButtonRegisterMouseClicked(evt);
127 gridBagConstraints = new java.awt.GridBagConstraints();
128 gridBagConstraints.gridx = 2;
129 gridBagConstraints.gridy = 8;
130 gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
131 getContentPane().add(gButtonRegister, gridBagConstraints);
133 gLabelRegister.setText("Not already registered?");
134 gridBagConstraints = new java.awt.GridBagConstraints();
135 gridBagConstraints.gridx = 0;
136 gridBagConstraints.gridy = 8;
137 gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
138 getContentPane().add(gLabelRegister, gridBagConstraints);
141 }// </editor-fold>//GEN-END:initComponents
143 private void gFieldNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldNameActionPerformed
144 // TODO add your handling code here:
145 }//GEN-LAST:event_gFieldNameActionPerformed
147 private void gButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gButtonLoginActionPerformed
148 // TODO add your handling code here:
149 }//GEN-LAST:event_gButtonLoginActionPerformed
151 private void gFieldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldPasswordActionPerformed
152 // TODO add your handling code here:
153 }//GEN-LAST:event_gFieldPasswordActionPerformed
155 private void gButtonLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonLoginMouseClicked
156 // TODO add your handling code here:
157 if (((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()))); //this.dispose();
158 else gFieldName.setText("Invalid Login...");
159 }//GEN-LAST:event_gButtonLoginMouseClicked
161 private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
162 // TODO add your handling code here:
163 }//GEN-LAST:event_formWindowClosed
165 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
166 // TODO add your handling code here:
167 ((ClientGUI)this.getOwner()).loginAbort();
168 }//GEN-LAST:event_formWindowClosing
170 private void gButtonRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonRegisterMouseClicked
171 // TODO add your handling code here:
172 ((ClientGUI)this.getOwner()).regiProfileDialog();
173 }//GEN-LAST:event_gButtonRegisterMouseClicked
176 * @param args the command line arguments
178 public static void main(String args[]) {
179 /* Set the Nimbus look and feel */
180 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
181 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
182 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
185 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
186 if ("Nimbus".equals(info.getName())) {
187 javax.swing.UIManager.setLookAndFeel(info.getClassName());
191 } catch (ClassNotFoundException ex) {
192 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
193 } catch (InstantiationException ex) {
194 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
195 } catch (IllegalAccessException ex) {
196 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
197 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
198 java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
203 /* Create and display the dialog */
204 java.awt.EventQueue.invokeLater(new Runnable() {
206 Login dialog = new Login(new javax.swing.JFrame(), true);
207 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
209 public void windowClosing(java.awt.event.WindowEvent e) {
213 dialog.setVisible(true);
218 // Variables declaration - do not modify//GEN-BEGIN:variables
219 private javax.swing.JButton gButtonLogin;
220 private javax.swing.JButton gButtonRegister;
221 private javax.swing.JTextField gFieldName;
222 private javax.swing.JPasswordField gFieldPassword;
223 private javax.swing.JLabel gLabelName;
224 private javax.swing.JLabel gLabelPassword;
225 private javax.swing.JLabel gLabelRegister;
226 private javax.swing.JLabel gLabelWSYD;
227 // End of variables declaration//GEN-END:variables