Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package concert.hall;
- import java.awt.Toolkit;
- import java.awt.event.WindowEvent;
- import javax.swing.JOptionPane;
- import javax.swing.JButton;
- public class Login1 extends javax.swing.JFrame {
- public Login1() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- loginButton = new javax.swing.JButton();
- usernameTxt = new javax.swing.JTextField();
- usernameLbl = new javax.swing.JLabel();
- passwordLbl = new javax.swing.JLabel();
- passwordTxt = new javax.swing.JPasswordField();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Admin Login");
- loginButton.setText("Login");
- loginButton.setName("loginButton"); // NOI18N
- loginButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- loginButtonActionPerformed(evt);
- }
- });
- usernameLbl.setText("Username");
- usernameLbl.setName(""); // NOI18N
- passwordLbl.setText("Password");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(28, 28, 28)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(usernameLbl)
- .addComponent(passwordLbl))
- .addGap(58, 58, 58)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(usernameTxt)
- .addComponent(loginButton)
- .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(35, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(51, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(usernameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(usernameLbl))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(passwordLbl)
- .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(loginButton)
- .addGap(31, 31, 31))
- );
- pack();
- }// </editor-fold>
- private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String password = passwordTxt.getText();
- String username = usernameTxt.getText();
- if(username.contains("admin")&& password.contains("pass")){
- usernameTxt.setText("");
- passwordTxt.setText("");
- close();
- // main m = new main();//change main to what your main frame is called
- // m.setVisable();
- }
- else
- {
- JButton source = (JButton) evt.getSource();
- JOptionPane.showMessageDialog(source, source.getText() + "Username or Password is incorrect. Please try again.");
- usernameTxt.setText("");
- passwordTxt.setText("");
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Login1().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton loginButton;
- private javax.swing.JLabel passwordLbl;
- private javax.swing.JPasswordField passwordTxt;
- private javax.swing.JLabel usernameLbl;
- private javax.swing.JTextField usernameTxt;
- // End of variables declaration
- private void close(){
- WindowEvent winClosing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement