Advertisement
Fahim_7861

Login

Nov 29th, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3.  
  4. import java.awt.Toolkit;
  5. import java.awt.event.WindowEvent;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11. import javax.swing.JFrame;
  12. import javax.swing.JOptionPane;
  13.  
  14.  
  15. public class Login extends javax.swing.JFrame {
  16.  
  17.  
  18.  
  19. private Connection connection=null;
  20. private PreparedStatement pst = null;
  21. private ResultSet resultSet = null;
  22.  
  23.  
  24. public Login() {
  25.  
  26.  
  27. initComponents();
  28.  
  29. init();
  30.  
  31. connection=JavaDbConnection.dbConnect();
  32. }
  33.  
  34. public void init()
  35. {
  36. setLocationRelativeTo(null);
  37. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  38. setResizable(false);
  39. }
  40.  
  41. public void close(){
  42. WindowEvent winClosingEvnt=new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
  43. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvnt);
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. /**
  52. * This method is called from within the constructor to initialize the form.
  53. * WARNING: Do NOT modify this code. The content of this method is always
  54. * regenerated by the Form Editor.
  55. */
  56. @SuppressWarnings("unchecked")
  57. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  58. private void initComponents() {
  59.  
  60. jLabel2 = new javax.swing.JLabel();
  61. jLabel1 = new javax.swing.JLabel();
  62. jPanel1 = new javax.swing.JPanel();
  63. Deshpass = new javax.swing.JPasswordField();
  64. jLabel3 = new javax.swing.JLabel();
  65. btnLogOn = new javax.swing.JButton();
  66. Password = new javax.swing.JLabel();
  67. FahimUsername = new javax.swing.JTextField();
  68. jLabel4 = new javax.swing.JLabel();
  69.  
  70. jLabel2.setIcon(new javax.swing.ImageIcon("F:\\DatabaseMysqlProject\\src\\image\\Coachnew.jpg")); // NOI18N
  71. jLabel2.setText("jLabel2");
  72.  
  73. jLabel1.setIcon(new javax.swing.ImageIcon("F:\\DatabaseMysqlProject\\src\\image\\Coachnew.jpg")); // NOI18N
  74.  
  75. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  76.  
  77. jPanel1.setBackground(new java.awt.Color(153, 204, 255));
  78. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Login ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rockwell Extra Bold", 3, 48), new java.awt.Color(255, 255, 255))); // NOI18N
  79.  
  80. jLabel3.setBackground(new java.awt.Color(51, 51, 255));
  81. jLabel3.setText("UserName");
  82.  
  83. btnLogOn.setText("Enter");
  84. btnLogOn.addActionListener(new java.awt.event.ActionListener() {
  85. public void actionPerformed(java.awt.event.ActionEvent evt) {
  86. btnLogOnActionPerformed(evt);
  87. }
  88. });
  89.  
  90. Password.setText("Password");
  91.  
  92. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  93. jPanel1.setLayout(jPanel1Layout);
  94. jPanel1Layout.setHorizontalGroup(
  95. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  96. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  97. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  98. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  99. .addComponent(jLabel3)
  100. .addComponent(Password, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
  101. .addGap(24, 24, 24)
  102. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  103. .addComponent(Deshpass)
  104. .addComponent(FahimUsername)
  105. .addComponent(btnLogOn, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
  106. .addGap(49, 49, 49))
  107. );
  108. jPanel1Layout.setVerticalGroup(
  109. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addGroup(jPanel1Layout.createSequentialGroup()
  111. .addGap(80, 80, 80)
  112. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  113. .addComponent(jLabel3)
  114. .addComponent(FahimUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  115. .addGap(18, 18, 18)
  116. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  117. .addComponent(Password)
  118. .addComponent(Deshpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  119. .addGap(18, 18, 18)
  120. .addComponent(btnLogOn)
  121. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  122. );
  123.  
  124. jLabel4.setIcon(new javax.swing.ImageIcon("F:\\DatabaseMysqlProject\\src\\image\\Coachnew.jpg")); // NOI18N
  125.  
  126. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  127. getContentPane().setLayout(layout);
  128. layout.setHorizontalGroup(
  129. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  131. .addComponent(jLabel4)
  132. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  133. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  134. );
  135. layout.setVerticalGroup(
  136. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  137. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  138. .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
  139. );
  140.  
  141. pack();
  142. }// </editor-fold>
  143.  
  144. private void btnLogOnActionPerformed(java.awt.event.ActionEvent evt) {
  145.  
  146. String sql = "select * from login where UserName= ? and Password =?";
  147.  
  148. try {
  149. pst = connection.prepareStatement(sql);
  150. pst.setString(1, FahimUsername.getText());
  151. pst.setString(2, Deshpass.getText());
  152. resultSet = pst.executeQuery();
  153. if (resultSet.next()) {
  154. close();
  155. Maa_CoachingDatabase obj = new Maa_CoachingDatabase();
  156. obj.setVisible(true);
  157.  
  158.  
  159. try {
  160. resultSet.close();
  161. pst.close();
  162. connection.close();
  163.  
  164. } catch (Exception e) {
  165. JOptionPane.showMessageDialog(rootPane, e);
  166. }
  167. } else {
  168. JOptionPane.showMessageDialog(rootPane, "UserName And Password is incorrect!");
  169.  
  170. }
  171.  
  172. } catch (Exception e) {
  173. JOptionPane.showMessageDialog(rootPane, e);
  174. }
  175.  
  176.  
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183. /**
  184. * @param args the command line arguments
  185. */
  186. public static void main(String args[]) {
  187. /* Set the Nimbus look and feel */
  188. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  189. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  190. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  191. */
  192. try {
  193. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  194. if ("Windows".equals(info.getName())) {
  195. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  196. break;
  197. }
  198. }
  199. } catch (ClassNotFoundException ex) {
  200. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  201. } catch (InstantiationException ex) {
  202. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  203. } catch (IllegalAccessException ex) {
  204. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  205. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  206. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  207. }
  208. //</editor-fold>
  209.  
  210. /* Create and display the form */
  211. java.awt.EventQueue.invokeLater(new Runnable() {
  212. public void run() {
  213. new Login().setVisible(true);
  214. }
  215. });
  216. }
  217.  
  218. // Variables declaration - do not modify
  219. private javax.swing.JPasswordField Deshpass;
  220. private javax.swing.JTextField FahimUsername;
  221. private javax.swing.JLabel Password;
  222. private javax.swing.JButton btnLogOn;
  223. private javax.swing.JLabel jLabel1;
  224. private javax.swing.JLabel jLabel2;
  225. private javax.swing.JLabel jLabel3;
  226. private javax.swing.JLabel jLabel4;
  227. private javax.swing.JPanel jPanel1;
  228. // End of variables declaration
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement