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 aplikasi;
- import database.Koneksi;
- import placeholder.Username;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.swing.JOptionPane;
- import javax.swing.ImageIcon;
- /**
- *
- * @author Firmansyah Helmi Kurniawan, Rizki Wiguna, Inesya Adella, Frans Davidson Mangapul Nababan
- */
- public class Login extends javax.swing.JFrame {
- /**
- * @return the user_id
- */
- Connection conn;
- Statement stat;
- ResultSet rs;
- String sql;
- String id;
- private static String s_username;
- /**
- * Creates new form NewJFrame
- */
- public Login() {
- initComponents();
- this.setLocationRelativeTo(null);
- ImageIcon icon = new ImageIcon("src/images/tokobuku.png");
- setIconImage(icon.getImage());
- Koneksi DB = new Koneksi();
- DB.config();
- conn = DB.conn;
- stat = DB.stm;
- //java_project | JAVATMJ@
- }
- public static String getUser_id() {
- return s_username;
- }
- /**
- * 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() {
- jPanel1 = new javax.swing.JPanel();
- jLabel3 = new javax.swing.JLabel();
- jPanel2 = new javax.swing.JPanel();
- lbl_login = new javax.swing.JLabel();
- TF_username = new Username();
- TF_password = new placeholder.Password();
- BTN_masuk = new javax.swing.JButton();
- lbl_daftar = new javax.swing.JLabel();
- lbl_login_icon = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("BUKU BOS!!!");
- setResizable(false);
- getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- jPanel1.setBackground(new java.awt.Color(166, 227, 233));
- jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/tokobuku.png"))); // NOI18N
- jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
- getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(284, 0, 300, 280));
- jPanel2.setBackground(new java.awt.Color(176, 224, 212));
- jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- lbl_login.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
- lbl_login.setText("Login");
- jPanel2.add(lbl_login, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 30, -1, -1));
- TF_username.setBackground(new java.awt.Color(227, 253, 253));
- TF_username.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
- jPanel2.add(TF_username, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 70, 151, 43));
- TF_username.getAccessibleContext().setAccessibleName("");
- TF_username.getAccessibleContext().setAccessibleDescription("");
- TF_password.setBackground(new java.awt.Color(227, 253, 253));
- TF_password.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
- TF_password.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- TF_passwordActionPerformed(evt);
- }
- });
- jPanel2.add(TF_password, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 120, 151, 43));
- BTN_masuk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/login_48px.png"))); // NOI18N
- BTN_masuk.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- BTN_masuk.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- BTN_masukActionPerformed(evt);
- }
- });
- jPanel2.add(BTN_masuk, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 170, 151, 48));
- lbl_daftar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add_user_male_48px.png"))); // NOI18N
- lbl_daftar.setToolTipText("");
- lbl_daftar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- lbl_daftar.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- lbl_daftarMouseClicked(evt);
- }
- });
- jPanel2.add(lbl_daftar, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 220, -1, 50));
- getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 290, 280));
- getContentPane().add(lbl_login_icon, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 229, -1, -1));
- pack();
- }// </editor-fold>
- private void TF_passwordActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void BTN_masukActionPerformed(java.awt.event.ActionEvent evt) {
- String username = TF_username.getText();
- String password = TF_password.getText();
- try {
- sql = "SELECT * FROM users WHERE username='"+username+"' AND password='"+password+"'";
- rs = stat.executeQuery(sql);
- if (rs.next()) {
- if (username.equals(rs.getString("username")) && password.equals(rs.getString("password"))) {
- JOptionPane.showMessageDialog(null, "Berhasil Login");
- s_username = rs.getString("username");
- new Home().setVisible(true);
- dispose();
- }
- } else {
- JOptionPane.showMessageDialog(null, "Username atau password salah");
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(this, e.getMessage());
- }
- }
- private void lbl_daftarMouseClicked(java.awt.event.MouseEvent evt) {
- // Register register = new Register(); Membuat instance object dari class Register
- // register.setVisible(true);
- new Register().setVisible(true);
- dispose();
- }
- /**
- * @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>
- //</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 BTN_masuk;
- private javax.swing.JTextField TF_password;
- private javax.swing.JTextField TF_username;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JLabel lbl_daftar;
- private javax.swing.JLabel lbl_login;
- private javax.swing.JLabel lbl_login_icon;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment