Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cabsystem;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- public class log extends javax.swing.JFrame {
- /**
- * Creates new form log
- */
- public log(java.awt.Frame parent, boolean modal) {
- initComponents();
- }
- log() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- un = new javax.swing.JTextField();
- pw = new javax.swing.JPasswordField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Login");
- jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
- jLabel1.setText("Log In");
- jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
- jLabel2.setText("Password");
- jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
- jLabel3.setText("User Name");
- pw.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- pwActionPerformed(evt);
- }
- });
- jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
- jButton1.setText("Cancel");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
- jButton2.setText("Log In");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(37, 37, 37)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(41, 41, 41)
- .addComponent(pw, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(85, 85, 85)
- .addComponent(jButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton1)
- .addGap(51, 51, 51)))
- .addGap(45, 45, 45))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(159, 159, 159)
- .addComponent(jLabel1)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(236, Short.MAX_VALUE)))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(26, 26, 26)
- .addComponent(jLabel1)
- .addGap(48, 48, 48)
- .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(pw, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addGap(37, 37, 37))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(101, 101, 101)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(159, Short.MAX_VALUE)))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void pwActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- ConnectDB c =new ConnectDB();
- ResultSet rs;
- String sql;
- String name;
- String password;
- String pword = null;
- String tp = null;
- name=un.getText();
- password=pw.getText();
- sql = "SELECT * FROM USER WHERE UNAME IS '"+name+"';";
- rs = c.conne(sql);
- try {
- while(rs.next()){
- name = rs.getString("UNAME");
- pword = rs.getString("PWORD");
- tp = rs.getString("UTYPE");
- }
- } catch (SQLException ex) {
- Logger.getLogger(log.class.getName()).log(Level.SEVERE, null, ex);}
- if(password.equals(pword)){
- if(tp.equals("admin")){
- new mpage().setVisible(true);
- this.setVisible(false);
- }
- else{
- new umpage().setVisible(true);
- this.setVisible(false);
- }
- }
- else{
- JOptionPane.showMessageDialog(null, "Invalid login details");
- }
- }
- /**
- * @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;package cabsystem;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- public class log extends javax.swing.JFrame {
- /**
- * Creates new form log
- */
- public log(java.awt.Frame parent, boolean modal) {
- initComponents();
- }
- log() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- un = new javax.swing.JTextField();
- pw = new javax.swing.JPasswordField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Login");
- jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
- jLabel1.setText("Log In");
- jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
- jLabel2.setText("Password");
- jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
- jLabel3.setText("User Name");
- pw.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- pwActionPerformed(evt);
- }
- });
- jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
- jButton1.setText("Cancel");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
- jButton2.setText("Log In");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(37, 37, 37)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(41, 41, 41)
- .addComponent(pw, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(85, 85, 85)
- .addComponent(jButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton1)
- .addGap(51, 51, 51)))
- .addGap(45, 45, 45))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(159, 159, 159)
- .addComponent(jLabel1)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(236, Short.MAX_VALUE)))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(26, 26, 26)
- .addComponent(jLabel1)
- .addGap(48, 48, 48)
- .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(pw, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addGap(37, 37, 37))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(101, 101, 101)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(159, Short.MAX_VALUE)))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void pwActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- ConnectDB c =new ConnectDB();
- ResultSet rs;
- String sql;
- String name;
- String password;
- String pword = null;
- String tp = null;
- name=un.getText();
- password=pw.getText();
- sql = "SELECT * FROM USER WHERE UNAME IS '"+name+"';";
- rs = c.conne(sql);
- try {
- while(rs.next()){
- name = rs.getString("UNAME");
- pword = rs.getString("PWORD");
- tp = rs.getString("UTYPE");
- }
- } catch (SQLException ex) {
- Logger.getLogger(log.class.getName()).log(Level.SEVERE, null, ex);}
- if(password.equals(pword)){
- if(tp.equals("admin")){
- new mpage().setVisible(true);
- this.setVisible(false);
- }
- else{
- new umpage().setVisible(true);
- this.setVisible(false);
- }
- }
- else{
- JOptionPane.showMessageDialog(null, "Invalid login details");
- }
- }
- /**
- * @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.set
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(log.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 log().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPasswordField pw;
- private javax.swing.JTextField un;
- // End of variables declaration
- }
- package cabsystem;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class ConnectDB {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost:3306/cabsystem";
- static final String USER = "root";
- static final String PASS = "";
- static Connection conn = null;
- static Statement stmt = null;
- static ResultSet rs;
- /**
- *
- * @param sql
- * @return
- */
- public static ResultSet conne(String sql) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(DB_URL,USER,PASS);
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- } catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
- }
- return rs;
- }
- public static void connu(String sql) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(DB_URL,USER,PASS);
- stmt = conn.createStatement();
- stmt.executeUpdate(sql);
- } catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement