Advertisement
pendekar_langit

formlogin

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