Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rentalmobil.user;
- import java.sql.*;
- import javax.swing.JOptionPane;
- /**
- *
- * @author surya
- */
- public class FormLOGINUSER extends javax.swing.JFrame {
- /**
- * Creates new form FormLOGINUSER
- */
- public FormLOGINUSER() {
- initComponents();
- }
- /**
- * 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() {
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- inputuser = new javax.swing.JTextField();
- inputpass = new javax.swing.JPasswordField();
- jButton3 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("LOGIN USER");
- jLabel2.setText("Username");
- jLabel3.setText("Password");
- jButton3.setText("Login");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel3))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton3)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(inputuser)
- .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(inputuser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(jButton3)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- Connection conn = koneksi.getconn();
- Statement stat = conn.createStatement();
- ResultSet res = stat.executeQuery("select * from tbuser order by id_user ");
- Object[] o = new Object[1];
- o[0] = res.getString("username");
- o[1] = res.getString("password");
- if (res.next()){
- if (inputuser.getText().equals(o[0]) && inputpass.getText().equals(o[1])){
- JOptionPane.showMessageDialog(rootPane, "Sukses Login Dengan User "+inputuser.getText());
- new MainMENUUSER().show();
- this.dispose();
- }else{
- JOptionPane.showMessageDialog(rootPane, "password salah");
- inputpass.setText("");
- inputpass.requestFocus();
- }
- }else{
- JOptionPane.showMessageDialog(rootPane, "Username belum terdaftar !!!");
- inputuser.setText("");
- inputpass.setText("");
- inputuser.requestFocus();
- }
- }catch (SQLException t){
- JOptionPane.showMessageDialog(rootPane, "Ada yang salah");
- }
- }
- /**
- * @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;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FormLOGINUSER.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FormLOGINUSER.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 FormLOGINUSER().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JPasswordField inputpass;
- private javax.swing.JTextField inputuser;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement