Anda di halaman 1dari 5

* To change this template, choose Tools | Templates * and open the template in the editor. * * JFrameLogin.

java *Created on 15 Apr 11, 23:25:43 * package dat.gui; import java.sql.*; import javax.swing.*; * @author joy0jay * public class JFrameLogin extends javax.swing.JFrame { /** Creates new form JFrameLogin * Statement Stm; Connection con; ResultSet RsUser; public JFrameLogin() { initComponents(); openDataBase(); //agar saat run database langsung terbaca } private void openDataBase() //untuk koneksi dengan database { try { Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/dbDAT","root" ,""); System.out.println("Koneksi Database Berhasil...!!"); } catch(ClassNotFoundException e) { System.out.println("Database Tidak Ditemukan"); } catch(Exception e) { System.out.println(e); } /** 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() { jLabel1 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtUserID = new javax.swing.JTextField(); txtPassword = new javax.swing.JPasswordField();

jMasuk = new javax.swing.JButton(); jBatal = new javax.swing.JButton(); jSeparator2 = new javax.swing.JSeparator(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 23)); jLabel1.setText("Masukan Data Pengguna"); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); jLabel2.setText("User ID"); jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); jLabel3.setText("Password"); jMasuk.setText("Masuk"); jMasuk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMasukActionPerformed(evt); } }); jBatal.setText("Batal"); jBatal.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jBatalActionPerformed(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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm ent.LEADING) .addGroup(layout.createSequentialGroup() .addGap(74, 74, 74) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addContainerGap(180, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm ent.TRAILING) .addComponent(jLabel2) .addComponent(jLabel3)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm ent.LEADING) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(jMasuk) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED ) .addComponent(jBatal)) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm ent.TRAILING, false) .addComponent(txtUserID, javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADIN G,javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED , 64, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 43 6, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 43 6, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, java x.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(24, 24, 24) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment. BASELINE) .addComponent(jLabel2) .addComponent(txtUserID, javax.swing.GroupLayout.PREFERRED_SIZE, 27, ja vax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment. BASELINE) .addComponent(jLabel3) .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(31, 31, 31) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequ entialGroup() .addGap(183, 183, 183) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment. BASELINE) .addComponent(jMasuk, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.M AX_VALUE) .addComponent(jBatal, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax .swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap()) ); pack(); }// </editor-fold> private void jBatalActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0);

} private void jMasukActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try String password; password = new String(txtPassword.getPassword()); String tUserId = txtUserID.getText(); Stm = con.createStatement(); RsUser = Stm.executeQuery("Select * from tuser where UserID = '"+tUserId +"'"+"and password = '"+password+"'"); int baris = 0; while(RsUser.next()) baris = RsUser.getRow(); } if(baris == 1) { dispose(); new JFrameMenu().setVisible(true); } else { JOptionPane.showMessageDialog(null, "User Id atau Password Tidak Cocok\ n '"+tUserId+"'\n'"+password+"'"); } } catch(Exception e) { JOptionPane.showMessageDialog(null, e); } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JFrameLogin().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jBatal; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JButton jMasuk; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JPasswordField txtPassword; private javax.swing.JTextField txtUserID;

// End of variables declaration }

Anda mungkin juga menyukai