Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. package concert.hall;
  2.  
  3. import java.awt.Toolkit;
  4. import java.awt.event.WindowEvent;
  5. import javax.swing.JOptionPane;
  6. import javax.swing.JButton;
  7.  
  8. public class Login1 extends javax.swing.JFrame {
  9.  
  10. public Login1() {
  11. initComponents();
  12. }
  13.  
  14. @SuppressWarnings("unchecked")
  15. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  16. private void initComponents() {
  17.  
  18. loginButton = new javax.swing.JButton();
  19. usernameTxt = new javax.swing.JTextField();
  20. usernameLbl = new javax.swing.JLabel();
  21. passwordLbl = new javax.swing.JLabel();
  22. passwordTxt = new javax.swing.JPasswordField();
  23.  
  24. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  25. setTitle("Admin Login");
  26.  
  27. loginButton.setText("Login");
  28. loginButton.setName("loginButton"); // NOI18N
  29. loginButton.addActionListener(new java.awt.event.ActionListener() {
  30. public void actionPerformed(java.awt.event.ActionEvent evt) {
  31. loginButtonActionPerformed(evt);
  32. }
  33. });
  34.  
  35. usernameLbl.setText("Username");
  36. usernameLbl.setName(""); // NOI18N
  37.  
  38. passwordLbl.setText("Password");
  39.  
  40. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  41. getContentPane().setLayout(layout);
  42. layout.setHorizontalGroup(
  43. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  44. .addGroup(layout.createSequentialGroup()
  45. .addGap(28, 28, 28)
  46. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  47. .addComponent(usernameLbl)
  48. .addComponent(passwordLbl))
  49. .addGap(58, 58, 58)
  50. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  51. .addComponent(usernameTxt)
  52. .addComponent(loginButton)
  53. .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
  54. .addContainerGap(35, Short.MAX_VALUE))
  55. );
  56. layout.setVerticalGroup(
  57. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  58. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  59. .addContainerGap(51, Short.MAX_VALUE)
  60. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  61. .addComponent(usernameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  62. .addComponent(usernameLbl))
  63. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  64. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  65. .addComponent(passwordLbl)
  66. .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  67. .addGap(18, 18, 18)
  68. .addComponent(loginButton)
  69. .addGap(31, 31, 31))
  70. );
  71.  
  72. pack();
  73. }// </editor-fold>
  74.  
  75. private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
  76. // TODO add your handling code here:
  77. String password = passwordTxt.getText();
  78. String username = usernameTxt.getText();
  79.  
  80. if(username.contains("admin")&& password.contains("pass")){
  81. usernameTxt.setText("");
  82. passwordTxt.setText("");
  83. close();
  84. // main m = new main();//change main to what your main frame is called
  85. // m.setVisable();
  86. }
  87. else
  88. {
  89. JButton source = (JButton) evt.getSource();
  90. JOptionPane.showMessageDialog(source, source.getText() + "Username or Password is incorrect. Please try again.");
  91. usernameTxt.setText("");
  92. passwordTxt.setText("");
  93. }
  94. }
  95.  
  96. /**
  97. * @param args the command line arguments
  98. */
  99. public static void main(String args[]) {
  100. /* Set the Nimbus look and feel */
  101. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  102. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  103. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  104. */
  105. try {
  106. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  107. if ("Nimbus".equals(info.getName())) {
  108. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  109. break;
  110. }
  111. }
  112. } catch (ClassNotFoundException ex) {
  113. java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  114. } catch (InstantiationException ex) {
  115. java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  116. } catch (IllegalAccessException ex) {
  117. java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  118. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  119. java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  120. }
  121. //</editor-fold>
  122.  
  123. /* Create and display the form */
  124. java.awt.EventQueue.invokeLater(new Runnable() {
  125. public void run() {
  126. new Login1().setVisible(true);
  127. }
  128. });
  129. }
  130.  
  131. // Variables declaration - do not modify
  132. private javax.swing.JButton loginButton;
  133. private javax.swing.JLabel passwordLbl;
  134. private javax.swing.JPasswordField passwordTxt;
  135. private javax.swing.JLabel usernameLbl;
  136. private javax.swing.JTextField usernameTxt;
  137. // End of variables declaration
  138.  
  139. private void close(){
  140. WindowEvent winClosing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
  141. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosing);
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement