/Users/johnr/Desktop/IA_14_-_Stage_P_Upload_all_2021-04-08/IBCompSciInternalAssessment Lara April 6th/src/ibcompsciinternalassessment/LoginScreenPopUp.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 package ibcompsciinternalassessment;
  7 import java.util.Arrays;
  8 
  9 /**
 10  *
 11  * @author 21258
 12  */
 13 public class LoginScreenPopUp extends javax.swing.JFrame {
 14 
 15     static String correctUsername  = "username";
 16     static char[] correctPassword  = new char[] {'p','a','s','s','w','o','r','d'};
 17     static boolean isCorrect = false;
 18     
 19     
 20     /**
 21      * Creates new form LoginScreenPopUp
 22      */
 23     public LoginScreenPopUp() {
 24         initComponents();
 25         usrnmTextBox.setText("");
 26         psswrdTextBox.setText("");
 27         incorrectCredLabel.setVisible(false);
 28     }
 29     
 30     public boolean getIsCorrect(){
 31         return isCorrect;
 32     }
 33 
 



Netbeans auto-generated GUI code pasted at the end.




135     
136     private void cancelButtonMouseReleased(java.awt.event.MouseEvent evt) {                                           
137         setVisible(false);
138     }                                          
139 
140     private void loginButtonMouseReleased(java.awt.event.MouseEvent evt) {                                          
141         String username  = usrnmTextBox.getText();
142         char[] password  = psswrdTextBox.getPassword();
143         
144         if(username.equals(correctUsername) && Arrays.equals(password, correctPassword)){
145             isCorrect = true;
146             incorrectCredLabel.setVisible(false);
147             setVisible(false);
148             usrnmTextBox.setText("");
149             psswrdTextBox.setText("");
150         }
151         else{
152             isCorrect = false;
153             incorrectCredLabel.setVisible(true);
154             usrnmTextBox.setText("");
155             psswrdTextBox.setText("");
156         }
157         
158         
159     }                                         
160 
161     
162     
163     
164     /**
165      * @param args the command line arguments
166      */
167     public static void main(String args[]) {
168         /* Set the Nimbus look and feel */
169         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
170         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
171          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
172          */
173         try {
174             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
175                 if ("Nimbus".equals(info.getName())) {
176                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
177                     break;
178                 }
179             }
180         } catch (ClassNotFoundException ex) {
181             java.util.logging.Logger.getLogger(LoginScreenPopUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
182         } catch (InstantiationException ex) {
183             java.util.logging.Logger.getLogger(LoginScreenPopUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
184         } catch (IllegalAccessException ex) {
185             java.util.logging.Logger.getLogger(LoginScreenPopUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
186         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
187             java.util.logging.Logger.getLogger(LoginScreenPopUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
188         }
189         //</editor-fold>
190 
191         /* Create and display the form */
192         java.awt.EventQueue.invokeLater(new Runnable() {
193             public void run() {
194                 new LoginScreenPopUp().setVisible(true);
195             }
196             
197         });
198     }
199 



Netbeans auto-generated GUI code:

34     /**
 35      * This method is called from within the constructor to initialize the form.
 36      * WARNING: Do NOT modify this code. The content of this method is always
 37      * regenerated by the Form Editor.
 38      */
 39     @SuppressWarnings("unchecked")
 40     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 41     private void initComponents() {
 42 
 43         psswrdLabel = new javax.swing.JLabel();
 44         title = new javax.swing.JLabel();
 45         psswrdTextBox = new javax.swing.JPasswordField();
 46         usrnmTextBox = new javax.swing.JTextField();
 47         usrnmLabel = new javax.swing.JLabel();
 48         incorrectCredLabel = new javax.swing.JLabel();
 49         cancelButton = new javax.swing.JButton();
 50         loginButton = new javax.swing.JButton();
 51 
 52         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 53 
 54         psswrdLabel.setFont(new java.awt.Font("Baghdad", 0, 17)); // NOI18N
 55         psswrdLabel.setText("password");
 56 
 57         title.setFont(new java.awt.Font("AppleGothic", 0, 30)); // NOI18N
 58         title.setText("LOGIN HERE");
 59 
 60         usrnmLabel.setFont(new java.awt.Font("Baghdad", 0, 17)); // NOI18N
 61         usrnmLabel.setText("username");
 62 
 63         incorrectCredLabel.setForeground(new java.awt.Color(173, 11, 38));
 64         incorrectCredLabel.setText("Sorry, but the username or password does not match any existing accounts with permission to view this page");
 65 
 66         cancelButton.setText("CANCEL");
 67         cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
 68             public void mouseReleased(java.awt.event.MouseEvent evt) {
 69                 cancelButtonMouseReleased(evt);
 70             }
 71         });
 72 
 73         loginButton.setText("LOGIN");
 74         loginButton.addMouseListener(new java.awt.event.MouseAdapter() {
 75             public void mouseReleased(java.awt.event.MouseEvent evt) {
 76                 loginButtonMouseReleased(evt);
 77             }
 78         });
 79 
 80         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 81         getContentPane().setLayout(layout);
 82         layout.setHorizontalGroup(
 83             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 84             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 85                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 86                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 87                     .addGroup(layout.createSequentialGroup()
 88                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 89                             .addComponent(usrnmLabel)
 90                             .addComponent(psswrdLabel))
 91                         .addGap(27, 27, 27)
 92                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 93                             .addComponent(usrnmTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
 94                             .addComponent(psswrdTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
 95                         .addGap(353, 353, 353))
 96                     .addGroup(layout.createSequentialGroup()
 97                         .addComponent(loginButton)
 98                         .addGap(56, 56, 56)
 99                         .addComponent(cancelButton)
100                         .addGap(345, 345, 345))))
101             .addGroup(layout.createSequentialGroup()
102                 .addGap(72, 72, 72)
103                 .addComponent(incorrectCredLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 705, javax.swing.GroupLayout.PREFERRED_SIZE)
104                 .addGap(0, 116, Short.MAX_VALUE))
105             .addGroup(layout.createSequentialGroup()
106                 .addGap(277, 277, 277)
107                 .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
108                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
109         );
110         layout.setVerticalGroup(
111             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112             .addGroup(layout.createSequentialGroup()
113                 .addGap(82, 82, 82)
114                 .addComponent(title)
115                 .addGap(32, 32, 32)
116                 .addComponent(incorrectCredLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
117                 .addGap(18, 18, 18)
118                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
119                     .addComponent(usrnmLabel)
120                     .addComponent(usrnmTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
121                 .addGap(33, 33, 33)
122                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
123                     .addComponent(psswrdLabel)
124                     .addComponent(psswrdTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
125                 .addGap(43, 43, 43)
126                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
127                     .addComponent(cancelButton)
128                     .addComponent(loginButton))
129                 .addContainerGap(174, Short.MAX_VALUE))
130         );
131 
132         pack();
133     }// </editor-fold>                        
134     




200     // Variables declaration - do not modify                     
201     private javax.swing.JButton cancelButton;
202     private javax.swing.JLabel incorrectCredLabel;
203     private javax.swing.JButton loginButton;
204     private javax.swing.JLabel psswrdLabel;
205     private javax.swing.JPasswordField psswrdTextBox;
206     private javax.swing.JLabel title;
207     private javax.swing.JLabel usrnmLabel;
208     private javax.swing.JTextField usrnmTextBox;
209     // End of variables declaration                   
210 }
211