SHARE
TWEET

Patient Login

a guest Feb 17th, 2020 241 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 hospital.management.system;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.JOptionPane;
  15.  
  16. /**
  17.  *
  18.  * @author Maria
  19.  */
  20. public class Main extends javax.swing.JFrame {
  21.     private Connection con;
  22.     public Main() {
  23.         initComponents();
  24.         DatabaseConnection dbc = DatabaseConnection.getDatabaseConnection();
  25.         con = dbc.getConnection();
  26.     }
  27.  
  28.     /**
  29.      * This method is called from within the constructor to initialize the form.
  30.      * WARNING: Do NOT modify this code. The content of this method is always
  31.      * regenerated by the Form Editor.
  32.      */
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  35.     private void initComponents() {
  36.  
  37.         jPanel2 = new javax.swing.JPanel();
  38.         jPanel1 = new javax.swing.JPanel();
  39.         jLabel1 = new javax.swing.JLabel();
  40.         jLabel2 = new javax.swing.JLabel();
  41.         jLabel3 = new javax.swing.JLabel();
  42.         us = new javax.swing.JTextField();
  43.         ps = new javax.swing.JPasswordField();
  44.         jButton1 = new javax.swing.JButton();
  45.         jButton2 = new javax.swing.JButton();
  46.         jButton3 = new javax.swing.JButton();
  47.         jButton4 = new javax.swing.JButton();
  48.         jLabel4 = new javax.swing.JLabel();
  49.         jLabel5 = new javax.swing.JLabel();
  50.  
  51.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  52.         setBackground(new java.awt.Color(255, 255, 255));
  53.         setUndecorated(true);
  54.         getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  55.  
  56.         jPanel2.setBackground(new java.awt.Color(153, 0, 51));
  57.         jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  58.  
  59.         jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  60.         jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  61.  
  62.         jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hospital/management/system/Patient.png"))); // NOI18N
  63.         jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, -140, 520, 550));
  64.  
  65.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  66.         jLabel2.setText("Password");
  67.         jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 120, -1, -1));
  68.  
  69.         jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  70.         jLabel3.setText("Username");
  71.         jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 60, -1, -1));
  72.         jPanel1.add(us, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 60, 350, 40));
  73.         jPanel1.add(ps, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 120, 350, 40));
  74.  
  75.         jButton1.setText("Login");
  76.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  77.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  78.                 jButton1ActionPerformed(evt);
  79.             }
  80.         });
  81.         jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 170, 260, 30));
  82.  
  83.         jButton2.setText("Sign up");
  84.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  85.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  86.                 jButton2ActionPerformed(evt);
  87.             }
  88.         });
  89.         jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 170, 90, 30));
  90.  
  91.         jPanel2.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 200, 1020, 250));
  92.  
  93.         jButton3.setText("STAFF LOGIN");
  94.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  95.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  96.                 jButton3ActionPerformed(evt);
  97.             }
  98.         });
  99.         jPanel2.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 550, -1, -1));
  100.  
  101.         jButton4.setText("EXIT");
  102.         jButton4.addActionListener(new java.awt.event.ActionListener() {
  103.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  104.                 jButton4ActionPerformed(evt);
  105.             }
  106.         });
  107.         jPanel2.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 550, 110, -1));
  108.  
  109.         jLabel4.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
  110.         jLabel4.setForeground(new java.awt.Color(255, 255, 255));
  111.         jLabel4.setText("ARRT MEDICAL CENTER");
  112.         jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 110, -1, -1));
  113.  
  114.         jLabel5.setFont(new java.awt.Font("Tahoma", 1, 100)); // NOI18N
  115.         jLabel5.setForeground(new java.awt.Color(255, 255, 255));
  116.         jLabel5.setText("+");
  117.         jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 10, 90, 80));
  118.  
  119.         getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1020, 590));
  120.  
  121.         setSize(new java.awt.Dimension(1017, 587));
  122.         setLocationRelativeTo(null);
  123.     }// </editor-fold>                        
  124.  
  125.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  126.                 char pass[];
  127.                 pass = ps.getPassword();
  128.                 String login = "Select * from opd_patient where user=? and pass=?";
  129.                 try {
  130.                     PreparedStatement pst = con.prepareStatement(login);
  131.                     pst.setString(1,us.getText());
  132.                     pst.setString(2,String.valueOf(pass));
  133.                     ResultSet rs = pst.executeQuery();
  134.                     if(rs.next()){
  135.                        Patient ap = new Patient();
  136.                        ap.id.setText(rs.getString("opd_id"));
  137.                        ap.a.setText(rs.getString("lastname"));
  138.                        ap.b.setText(rs.getString("firstname"));
  139.                        ap.name.setText(rs.getString("firstname"));
  140.                        ap.c.setText(rs.getString("contact"));
  141.                        ap.d.setText(rs.getString("email"));
  142.                        ap.setVisible(true);
  143.                        dispose();
  144.                     }
  145.                     else{
  146.                         JOptionPane.showMessageDialog(null,"Invalid Username/Password");
  147.                     }
  148.                 } catch (SQLException ex) {
  149.                     Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
  150.                 }
  151.     }                                        
  152.  
  153.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  154.         Signup su = new Signup();
  155.         su.setVisible(true);
  156.         dispose();
  157.     }                                        
  158.  
  159.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  160.         login log = new login();
  161.         log.setVisible(true);
  162.         dispose();
  163.     }                                        
  164.  
  165.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  166.         dispose();
  167.     }                                        
  168.  
  169.     /**
  170.      * @param args the command line arguments
  171.      */
  172.     public static void main(String args[]) {
  173.         /* Set the Nimbus look and feel */
  174.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  175.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  176.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  177.          */
  178.         try {
  179.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  180.                 if ("Nimbus".equals(info.getName())) {
  181.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  182.                     break;
  183.                 }
  184.             }
  185.         } catch (ClassNotFoundException ex) {
  186.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  187.         } catch (InstantiationException ex) {
  188.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  189.         } catch (IllegalAccessException ex) {
  190.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  191.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  192.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  193.         }
  194.         //</editor-fold>
  195.  
  196.         /* Create and display the form */
  197.         java.awt.EventQueue.invokeLater(new Runnable() {
  198.             public void run() {
  199.                 new Main().setVisible(true);
  200.             }
  201.         });
  202.     }
  203.  
  204.     // Variables declaration - do not modify                    
  205.     private javax.swing.JButton jButton1;
  206.     private javax.swing.JButton jButton2;
  207.     private javax.swing.JButton jButton3;
  208.     private javax.swing.JButton jButton4;
  209.     private javax.swing.JLabel jLabel1;
  210.     private javax.swing.JLabel jLabel2;
  211.     private javax.swing.JLabel jLabel3;
  212.     private javax.swing.JLabel jLabel4;
  213.     private javax.swing.JLabel jLabel5;
  214.     private javax.swing.JPanel jPanel1;
  215.     private javax.swing.JPanel jPanel2;
  216.     private javax.swing.JPasswordField ps;
  217.     private javax.swing.JTextField us;
  218.     // End of variables declaration                  
  219. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top