/Users/19942/NetBeansProjects/Material Management/src/MaterialManagement_GUI/Login.java

  1 /*

  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.

  5  */

  6 

  7 package MaterialManagement_GUI;

  8 

  9 import java.awt.event.WindowEvent;

 10 

 11 //import packages for warning windows

 12 import javax.swing.JOptionPane;

 13 import static javax.swing.JOptionPane.ERROR_MESSAGE;

 14 

 15 //import all the accounts

 16 

 17 /**

 18  *

 19  * @author 19942

 20  */

 21 public class Login extends javax.swing.JFrame {

 22 

 23     /** Creates new form Login */

 24     public Login() {

 25         initComponents();

 26     }

 27 

 28     /** This method is called from within the constructor to

 29      * initialize the form.

 30      * WARNING: Do NOT modify this code. The content of this method is

 31      * always regenerated by the Form Editor.

 32      */

 33     @SuppressWarnings("unchecked")

 252     

253     

254     public void studentA(){

255         positionComboBox_L.setSelectedIndex(0);

256         passwordField_L.setText(null);

257         systemExit();

258         StudentA show = new StudentA();

259         show.setVisible(true);

260     }

261     

262     private void systemExit(){

263         //Close this window without ending the entire program

264         WindowEvent winClosing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);

265         winClosing.getWindow().hide();

266     }

267     

268     public void studentB(){

269         positionComboBox_L.setSelectedIndex(0);

270         passwordField_L.setText(null);

271         systemExit();

272         StudentB show = new StudentB();

273         show.setVisible(true);

274     }

275     

276     public void studentC(){

277         positionComboBox_L.setSelectedIndex(0);

278         passwordField_L.setText(null);

279         systemExit();

280         StudentC show = new StudentC();

281         show.setVisible(true);

282     }

283     

284     public void studentD(){

285         positionComboBox_L.setSelectedIndex(0);

286         passwordField_L.setText(null);

287         systemExit();

288         StudentD show = new StudentD();

289         show.setVisible(true);

290     }

291     

292     public void studentE(){

293         positionComboBox_L.setSelectedIndex(0);

294         passwordField_L.setText(null);

295         systemExit();

296         StudentE show = new StudentE();

297         show.setVisible(true);

298     }

299     

300     public void teacher(){

301         positionComboBox_L.setSelectedIndex(0);

302         passwordField_L.setText(null);

303         systemExit();

304         Teacher show = new Teacher();

305         show.setVisible(true);

306     }

307 }

308 







 Auto Generated Code by NetBeans

34     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

 35     private void initComponents() {

 36 

 37         jPanel1 = new javax.swing.JPanel();

 38         jLabel1 = new javax.swing.JLabel();

 39         jPanel2 = new javax.swing.JPanel();

 40         jLabel2 = new javax.swing.JLabel();

 41         positionComboBox_L = new javax.swing.JComboBox<>();

 42         jLabel3 = new javax.swing.JLabel();

 43         passwordField_L = new javax.swing.JPasswordField();

 44         loginButton_L = new javax.swing.JButton();

 45         resetButton_L = new javax.swing.JButton();

 46         exitButton_L = new javax.swing.JButton();

 47 

 48         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 49 

 50         jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N

 51         jLabel1.setText("Login Page");

 52 

 53         jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));

 54 

 55         jLabel2.setText("Users's Position");

 56 

 57         positionComboBox_L.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Team 8861A", "Team 8861B", "Team 8861C", "Team 8861D", "Team 8861E", "Teacher" }));

 58 

 59         jLabel3.setText("Password");

 60 

 61         loginButton_L.setText("Login");

 62         loginButton_L.addMouseListener(new java.awt.event.MouseAdapter() {

 63             public void mouseReleased(java.awt.event.MouseEvent evt) {

 64                 loginButton_LMouseReleased(evt);

 65             }

 66         });

 67 

 68         resetButton_L.setText("Reset");

 69         resetButton_L.addMouseListener(new java.awt.event.MouseAdapter() {

 70             public void mouseReleased(java.awt.event.MouseEvent evt) {

 71                 resetButton_LMouseReleased(evt);

 72             }

 73         });

 74 

 75         exitButton_L.setText("Exit");

 76         exitButton_L.addMouseListener(new java.awt.event.MouseAdapter() {

 77             public void mouseReleased(java.awt.event.MouseEvent evt) {

 78                 exitButton_LMouseReleased(evt);

 79             }

 80         });

 81 

 82         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

 83         jPanel2.setLayout(jPanel2Layout);

 84         jPanel2Layout.setHorizontalGroup(

 85             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 86             .addGroup(jPanel2Layout.createSequentialGroup()

 87                 .addGap(64, 64, 64)

 88                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

 89                     .addComponent(loginButton_L, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

 90                     .addComponent(jLabel2)

 91                     .addComponent(jLabel3))

 92                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

 93                     .addGroup(jPanel2Layout.createSequentialGroup()

 94                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

 95                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

 96                             .addComponent(positionComboBox_L, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

 97                             .addComponent(passwordField_L, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)))

 98                     .addGroup(jPanel2Layout.createSequentialGroup()

 99                         .addGap(54, 54, 54)

100                         .addComponent(resetButton_L, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)

101                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)

102                         .addComponent(exitButton_L, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))

103                 .addGap(57, 57, 57))

104         );

105         jPanel2Layout.setVerticalGroup(

106             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

107             .addGroup(jPanel2Layout.createSequentialGroup()

108                 .addGap(47, 47, 47)

109                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

110                     .addComponent(jLabel2)

111                     .addComponent(positionComboBox_L, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

112                 .addGap(35, 35, 35)

113                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

114                     .addComponent(jLabel3)

115                     .addComponent(passwordField_L, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

116                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)

117                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

118                     .addComponent(loginButton_L)

119                     .addComponent(exitButton_L)

120                     .addComponent(resetButton_L))

121                 .addGap(43, 43, 43))

122         );

123 

124         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

125         jPanel1.setLayout(jPanel1Layout);

126         jPanel1Layout.setHorizontalGroup(

127             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

128             .addGroup(jPanel1Layout.createSequentialGroup()

129                 .addContainerGap()

130                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

131                 .addContainerGap())

132             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()

133                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

134                 .addComponent(jLabel1)

135                 .addGap(202, 202, 202))

136         );

137         jPanel1Layout.setVerticalGroup(

138             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

139             .addGroup(jPanel1Layout.createSequentialGroup()

140                 .addContainerGap(51, Short.MAX_VALUE)

141                 .addComponent(jLabel1)

142                 .addGap(39, 39, 39)

143                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

144                 .addGap(34, 34, 34))

145         );

146 

147         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

148         getContentPane().setLayout(layout);

149         layout.setHorizontalGroup(

150             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

151             .addGroup(layout.createSequentialGroup()

152                 .addContainerGap()

153                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

154                 .addContainerGap())

155         );

156         layout.setVerticalGroup(

157             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

158             .addGroup(layout.createSequentialGroup()

159                 .addContainerGap()

160                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

161                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

162         );

163 

164         pack();

165     }// </editor-fold>                        

166 

167     private void resetButton_LMouseReleased(java.awt.event.MouseEvent evt) {                                            

168         // reset all the information typed in the text field and combo box.

169         positionComboBox_L.setSelectedIndex(0);

170         passwordField_L.setText(null);

171     }                                           

172 

173     private void exitButton_LMouseReleased(java.awt.event.MouseEvent evt) {                                           

174         System.exit(0);

175     }                                          

176 

177     private void loginButton_LMouseReleased(java.awt.event.MouseEvent evt) {                                            

178         

179         String password = passwordField_L.getText();

180         String position = (String) positionComboBox_L.getSelectedItem();

181         if(passwordField_L.getText().equals("8861A") && positionComboBox_L.getSelectedItem().equals("Team 8861A")) {

182             studentA();//login account for student A

183         }

184         else if(passwordField_L.getText().equals("8861B") && positionComboBox_L.getSelectedItem().equals("Team 8861B")) {

185             studentB();//login account for student B

186         }

187         else if(passwordField_L.getText().equals("8861C") && positionComboBox_L.getSelectedItem().equals("Team 8861C")) {

188             studentC();//login account for student C

189         }

190         else if(passwordField_L.getText().equals("8861D") && positionComboBox_L.getSelectedItem().equals("Team 8861D")) {

191             studentD();//login account for student D

192         }

193         else if(passwordField_L.getText().equals("8861E") && positionComboBox_L.getSelectedItem().equals("Team 8861E")) {

194             studentE();//login account for student E

195         }

196         else if(passwordField_L.getText().equals("Teacher") && positionComboBox_L.getSelectedItem().equals("Teacher")) {

197             teacher();//login account for teacher

198         }else{

199             JOptionPane.showMessageDialog(null, "Password is incorrect", "Error", ERROR_MESSAGE);

200             //this will output an error message if the password is incorrect. 

201         }

202     }                                           

203 

204     /**

205      * @param args the command line arguments

206      */

207     public static void main(String args[]) {

208         /* Set the Nimbus look and feel */

209         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

210         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

211          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 

212          */

213         try {

214             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

215                 if ("Nimbus".equals(info.getName())) {

216                     javax.swing.UIManager.setLookAndFeel(info.getClassName());

217                     break;

218                 }

219             }

220         } catch (ClassNotFoundException ex) {

221             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

222         } catch (InstantiationException ex) {

223             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

224         } catch (IllegalAccessException ex) {

225             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

226         } catch (javax.swing.UnsupportedLookAndFeelException ex) {

227             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

228         }

229         //</editor-fold>

230 

231         /* Create and display the form */

232         java.awt.EventQueue.invokeLater(new Runnable() {

233             public void run() {

234                 new Login().setVisible(true);

235             }

236         });

237     }

238 

239     // Variables declaration - do not modify                     

240     private javax.swing.JButton exitButton_L;

241     private javax.swing.JLabel jLabel1;

242     private javax.swing.JLabel jLabel2;

243     private javax.swing.JLabel jLabel3;

244     private javax.swing.JPanel jPanel1;

245     private javax.swing.JPanel jPanel2;

246     private javax.swing.JButton loginButton_L;

247     private javax.swing.JPasswordField passwordField_L;

248     private javax.swing.JComboBox<String> positionComboBox_L;

249     private javax.swing.JButton resetButton_L;

250     // End of variables declaration                   

251