Advertisement
pendekar_langit

FormLOGINUSER

Nov 22nd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.24 KB | None | 0 0
  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.  
  7. package rentalmobil.user;
  8. import java.sql.Driver;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12. import java.sql.ResultSet;
  13. import java.sql.Statement;
  14. import java.sql.PreparedStatement;
  15. import javax.swing.JOptionPane;
  16. /**
  17.  *
  18.  * @author surya
  19.  */
  20. public class FormLOGINUSER extends javax.swing.JFrame {
  21. public Connection conn;
  22. public Statement stat;
  23. public ResultSet res;
  24.  
  25.     /**
  26.      * Creates new form FormLOGINUSER
  27.      */
  28.     public FormLOGINUSER() {
  29.         initComponents();
  30.     }
  31.  
  32.     /**
  33.      * This method is called from within the constructor to initialize the form.
  34.      * WARNING: Do NOT modify this code. The content of this method is always
  35.      * regenerated by the Form Editor.
  36.      */
  37.     @SuppressWarnings("unchecked")
  38.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  39.     private void initComponents() {
  40.  
  41.         jLabel2 = new javax.swing.JLabel();
  42.         jLabel3 = new javax.swing.JLabel();
  43.         inputuser = new javax.swing.JTextField();
  44.         inputpass = new javax.swing.JPasswordField();
  45.         jButton3 = new javax.swing.JButton();
  46.  
  47.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  48.         setTitle("LOGIN USER");
  49.  
  50.         jLabel2.setText("Username");
  51.  
  52.         jLabel3.setText("Password");
  53.  
  54.         jButton3.setText("Login");
  55.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  56.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  57.                 jButton3ActionPerformed(evt);
  58.             }
  59.         });
  60.  
  61.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  62.         getContentPane().setLayout(layout);
  63.         layout.setHorizontalGroup(
  64.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  65.             .addGroup(layout.createSequentialGroup()
  66.                 .addContainerGap()
  67.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  68.                     .addComponent(jLabel2)
  69.                     .addComponent(jLabel3))
  70.                 .addGap(18, 18, 18)
  71.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  72.                     .addComponent(jButton3)
  73.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  74.                         .addComponent(inputuser)
  75.                         .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
  76.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  77.         );
  78.         layout.setVerticalGroup(
  79.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  80.             .addGroup(layout.createSequentialGroup()
  81.                 .addContainerGap()
  82.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  83.                     .addComponent(jLabel2)
  84.                     .addComponent(inputuser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  85.                 .addGap(18, 18, 18)
  86.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  87.                     .addComponent(jLabel3)
  88.                     .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  89.                 .addGap(18, 18, 18)
  90.                 .addComponent(jButton3)
  91.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  92.         );
  93.  
  94.         pack();
  95.     }// </editor-fold>                        
  96.  
  97.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  98.         // TODO add your handling code here:
  99.        try{
  100.            
  101.            res = stat.executeQuery("select * from tbuser where "+"username ='"+inputuser.getText()+"'");
  102.            if (res.next()){
  103.                if (inputpass.getText().equals(res.getString("password"))){
  104.                    JOptionPane.showMessageDialog(rootPane, "Sukses Login Dengan User "+inputuser.getText());
  105.                     new MainMENUUSER().show();
  106.                     this.dispose();
  107.                }else{
  108.                    JOptionPane.showMessageDialog(rootPane, "password salah");
  109.                    inputpass.setText("");
  110.                    inputpass.requestFocus();
  111.                }
  112.            }else{
  113.                JOptionPane.showMessageDialog(rootPane, "Username belum terdaftar !!!");
  114.                inputuser.setText("");
  115.                inputpass.setText("");
  116.                inputuser.requestFocus();
  117.            }
  118.        }catch (SQLException e){
  119.            JOptionPane.showMessageDialog(rootPane, "Ada yang salah");
  120.        }
  121.                  
  122.     }                                        
  123.        
  124.     /**
  125.      * @param args the command line arguments
  126.      */
  127.     public static void main(String args[]) {
  128.         /* Set the Nimbus look and feel */
  129.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  130.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  131.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  132.          */
  133.         try {
  134.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  135.                 if ("Nimbus".equals(info.getName())) {
  136.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  137.                     break;
  138.                 }
  139.             }
  140.         } catch (ClassNotFoundException ex) {
  141.             java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  142.         } catch (InstantiationException ex) {
  143.             java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  144.         } catch (IllegalAccessException ex) {
  145.             java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  146.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  147.             java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  148.         }
  149.         //</editor-fold>
  150.  
  151.         /* Create and display the form */
  152.         java.awt.EventQueue.invokeLater(new Runnable() {
  153.             public void run() {
  154.                 new FormLOGINUSER().setVisible(true);
  155.             }
  156.         });
  157.     }
  158.  
  159.     // Variables declaration - do not modify                    
  160.     private javax.swing.JPasswordField inputpass;
  161.     private javax.swing.JTextField inputuser;
  162.     private javax.swing.JButton jButton3;
  163.     private javax.swing.JLabel jLabel2;
  164.     private javax.swing.JLabel jLabel3;
  165.     // End of variables declaration                  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement