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 rental;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- import java.sql.ResultSet;
- import javax.swing.JOptionPane;
- /**
- *
- * @author ECS
- */
- public class login extends javax.swing.JFrame {
- koneksi kn = new koneksi();
- Connection conn;
- Statement stt;
- ResultSet rs;
- String sql;
- /**
- * Creates new form login
- */
- public login() {
- 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() {
- jComboBox1 = new javax.swing.JComboBox();
- panel2 = new java.awt.Panel();
- tpas = new javax.swing.JPasswordField();
- tnama = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- panel2.setBackground(new java.awt.Color(102, 204, 0));
- tpas.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- tpasActionPerformed(evt);
- }
- });
- tnama.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- tnamaActionPerformed(evt);
- }
- });
- jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
- jLabel2.setForeground(new java.awt.Color(255, 255, 255));
- jLabel2.setText("USERNAME");
- jLabel3.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(255, 255, 255));
- jLabel3.setText("PASSWORD");
- jButton1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
- jButton1.setText("LOGIN");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
- jButton2.setText("EXIT");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jLabel1.setBackground(new java.awt.Color(255, 51, 255));
- jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 24)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(255, 0, 204));
- jLabel1.setText("SILAHKAN LOGIN");
- javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
- panel2.setLayout(panel2Layout);
- panel2Layout.setHorizontalGroup(
- panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(panel2Layout.createSequentialGroup()
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(panel2Layout.createSequentialGroup()
- .addGap(141, 141, 141)
- .addComponent(jLabel1))
- .addGroup(panel2Layout.createSequentialGroup()
- .addGap(74, 74, 74)
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addGap(38, 38, 38)
- .addComponent(tnama, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(panel2Layout.createSequentialGroup()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton2))
- .addComponent(tpas, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))))))
- .addContainerGap(79, Short.MAX_VALUE))
- );
- panel2Layout.setVerticalGroup(
- panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(panel2Layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addGap(13, 13, 13)
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(tnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(tpas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(50, 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(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(panel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void jButton2ActionPerformed(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:
- try {
- sql = "SELECT * FROM user WHERE username='"+tnama.getText()+"' AND password='"+tpas.getText()+"'";
- stt = (Statement) kn.logon().createStatement();
- rs = stt.executeQuery(sql);
- if (rs.next()) {
- if (tnama.getText().equals(rs.getString("username"))&& tpas.getText().equals("password"));{
- JOptionPane.showMessageDialog(null, "Berhasil Login");
- new hlmnawal().setVisible(true);
- this.dispose();
- }
- }else{
- }
- } catch (Exception e) {
- }
- }
- private void tpasActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void tnamaActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @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(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(login.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 login().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private java.awt.Panel panel2;
- private javax.swing.JTextField tnama;
- private javax.swing.JPasswordField tpas;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement