Mr-roz3r

Register.java

Jul 15th, 2021
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.81 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. package aplikasi;
  7.  
  8. import database.Koneksi;
  9. import placeholder.Username;
  10. import placeholder.Email;
  11. import placeholder.Nama;
  12. import placeholder.Nomor;
  13. import java.sql.Connection;
  14. import java.sql.ResultSet;
  15. import java.sql.Statement;
  16. import java.time.LocalDateTime;
  17. import java.time.format.DateTimeFormatter;
  18. import javax.swing.JOptionPane;
  19.  
  20. /**
  21.  *
  22.  * @author Firmansyah Helmi Kurniawan, Rizki Wiguna, Inesya Adella, Frans Davidson Mangapul Nababan
  23.  */
  24. public class Register extends javax.swing.JFrame {
  25.     Connection conn;
  26.     Statement stat;
  27.     ResultSet rs;
  28.     String sql;
  29.    
  30.     /**
  31.      * Creates new form NewJFrame
  32.      */
  33.     public Register() {
  34.         initComponents();
  35.         this.setLocationRelativeTo(null);
  36.         Koneksi DB = new Koneksi();
  37.         DB.config();
  38.         conn = DB.conn;
  39.         stat = DB.stm;
  40.     }
  41.  
  42.     /**
  43.      * This method is called from within the constructor to initialize the form.
  44.      * WARNING: Do NOT modify this code. The content of this method is always
  45.      * regenerated by the Form Editor.
  46.      */
  47.     @SuppressWarnings("unchecked")
  48.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  49.     private void initComponents() {
  50.  
  51.         TF_password2 = new placeholder.Password();
  52.         jLabel2 = new javax.swing.JLabel();
  53.         jPanel2 = new javax.swing.JPanel();
  54.         TF_nama = new Nama();
  55.         TF_username = new placeholder.Username();
  56.         BTN_masuk = new javax.swing.JButton();
  57.         lbl_login = new javax.swing.JLabel();
  58.         TF_password = new placeholder.Password();
  59.         TF_email = new placeholder.Email();
  60.         TF_nomor = new placeholder.Nomor();
  61.         jLabel1 = new javax.swing.JLabel();
  62.         lbl_login_icon = new javax.swing.JLabel();
  63.  
  64.         TF_password2.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  65.         TF_password2.addActionListener(new java.awt.event.ActionListener() {
  66.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  67.                 TF_password2ActionPerformed(evt);
  68.             }
  69.         });
  70.  
  71.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  72.         setTitle("Aplikasi");
  73.         setResizable(false);
  74.         getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  75.  
  76.         jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/back_to_48px.png"))); // NOI18N
  77.         jLabel2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  78.         jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
  79.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  80.                 jLabel2MouseClicked(evt);
  81.             }
  82.         });
  83.         getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));
  84.  
  85.         jPanel2.setBackground(new java.awt.Color(176, 224, 212));
  86.         jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  87.  
  88.         TF_nama.setBackground(new java.awt.Color(227, 253, 253));
  89.         TF_nama.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  90.         jPanel2.add(TF_nama, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 70, 151, 43));
  91.         TF_nama.getAccessibleContext().setAccessibleName("");
  92.         TF_nama.getAccessibleContext().setAccessibleDescription("");
  93.  
  94.         TF_username.setBackground(new java.awt.Color(227, 253, 253));
  95.         TF_username.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  96.         TF_username.addActionListener(new java.awt.event.ActionListener() {
  97.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  98.                 TF_usernameActionPerformed(evt);
  99.             }
  100.         });
  101.         jPanel2.add(TF_username, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 70, 151, 43));
  102.  
  103.         BTN_masuk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/login_48px.png"))); // NOI18N
  104.         BTN_masuk.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  105.         BTN_masuk.addActionListener(new java.awt.event.ActionListener() {
  106.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  107.                 BTN_masukActionPerformed(evt);
  108.             }
  109.         });
  110.         jPanel2.add(BTN_masuk, new org.netbeans.lib.awtextra.AbsoluteConstraints(411, 190, 50, 40));
  111.  
  112.         lbl_login.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  113.         lbl_login.setText("Register");
  114.         jPanel2.add(lbl_login, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 20, 80, -1));
  115.  
  116.         TF_password.setBackground(new java.awt.Color(227, 253, 253));
  117.         TF_password.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  118.         TF_password.addActionListener(new java.awt.event.ActionListener() {
  119.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  120.                 TF_passwordActionPerformed(evt);
  121.             }
  122.         });
  123.         jPanel2.add(TF_password, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 130, 151, 43));
  124.  
  125.         TF_email.setBackground(new java.awt.Color(227, 253, 253));
  126.         TF_email.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  127.         TF_email.addActionListener(new java.awt.event.ActionListener() {
  128.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  129.                 TF_emailActionPerformed(evt);
  130.             }
  131.         });
  132.         jPanel2.add(TF_email, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 190, 300, 43));
  133.  
  134.         TF_nomor.setBackground(new java.awt.Color(227, 253, 253));
  135.         TF_nomor.setFont(new java.awt.Font("Segoe UI Historic", 1, 18)); // NOI18N
  136.         TF_nomor.addActionListener(new java.awt.event.ActionListener() {
  137.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  138.                 TF_nomorActionPerformed(evt);
  139.             }
  140.         });
  141.         jPanel2.add(TF_nomor, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 130, 151, 43));
  142.  
  143.         jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/awan.png"))); // NOI18N
  144.         jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
  145.  
  146.         getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 580, 280));
  147.         getContentPane().add(lbl_login_icon, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 229, -1, -1));
  148.  
  149.         pack();
  150.     }// </editor-fold>                        
  151.  
  152.     private void TF_usernameActionPerformed(java.awt.event.ActionEvent evt) {                                            
  153.         // TODO add your handling code here:
  154.     }                                          
  155.  
  156.     private void BTN_masukActionPerformed(java.awt.event.ActionEvent evt) {                                          
  157.         String username = TF_username.getText();
  158.         String password = TF_password.getText();
  159.         String email = TF_email.getText();
  160.         String nomor = TF_nomor.getText();
  161.         String nama = TF_nama.getText();
  162.         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");  
  163.         LocalDateTime now = LocalDateTime.now();
  164.         int saldo = 0;
  165.        
  166.         try {
  167.             if (username.isEmpty() || password.isEmpty() || email.isEmpty() || nomor.isEmpty() || nama.isEmpty()) {
  168.                 JOptionPane.showMessageDialog(null, "Data yang anda isi harus lengkap!", "Peringatan", JOptionPane.WARNING_MESSAGE);
  169.             }else{
  170.                 sql = "INSERT INTO users (`username`, `password`, `email`, `phone`, `name`, `saldo`, `tanggal`) VALUES ('"+username+"', '"+password+"', '"+email+"', "+nomor+", '"+nama+"', '"+saldo+"', '"+dtf.format(now)+"')";
  171.                 int execute = stat.executeUpdate(sql);
  172.                 JOptionPane.showMessageDialog(null, "Pendaftaran Berhasil, Silakan Login!");
  173.                 new Login().setVisible(true);
  174.                 dispose();
  175.             }
  176.         } catch (Exception e) {
  177.             JOptionPane.showMessageDialog(null, "Username/Email/Phone sudah terdaftar!", "Peringatan", JOptionPane.WARNING_MESSAGE);
  178.         }
  179.     }                                        
  180.  
  181.     private void TF_passwordActionPerformed(java.awt.event.ActionEvent evt) {                                            
  182.         // TODO add your handling code here:
  183.     }                                          
  184.  
  185.     private void TF_password2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  186.         // TODO add your handling code here:
  187.     }                                            
  188.  
  189.     private void TF_emailActionPerformed(java.awt.event.ActionEvent evt) {                                        
  190.         // TODO add your handling code here:
  191.     }                                        
  192.  
  193.     private void TF_nomorActionPerformed(java.awt.event.ActionEvent evt) {                                        
  194.         // TODO add your handling code here:
  195.     }                                        
  196.  
  197.     private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                    
  198.         new Login().setVisible(true);
  199.         dispose();
  200.     }                                    
  201.  
  202.     /**
  203.      * @param args the command line arguments
  204.      */
  205.     public static void main(String args[]) {
  206.         /* Set the Nimbus look and feel */
  207.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  208.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  209.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  210.          */
  211.         try {
  212.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  213.                 if ("Nimbus".equals(info.getName())) {
  214.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  215.                     break;
  216.                 }
  217.             }
  218.         } catch (ClassNotFoundException ex) {
  219.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  220.         } catch (InstantiationException ex) {
  221.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  222.         } catch (IllegalAccessException ex) {
  223.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  224.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  225.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  226.         }
  227.         //</editor-fold>
  228.         //</editor-fold>
  229.         //</editor-fold>
  230.         //</editor-fold>
  231.  
  232.         /* Create and display the form */
  233.         java.awt.EventQueue.invokeLater(new Runnable() {
  234.             public void run() {
  235.                 new Register().setVisible(true);
  236.             }
  237.         });
  238.     }
  239.  
  240.     // Variables declaration - do not modify                    
  241.     private javax.swing.JButton BTN_masuk;
  242.     private javax.swing.JTextField TF_email;
  243.     private javax.swing.JTextField TF_nama;
  244.     private javax.swing.JTextField TF_nomor;
  245.     private javax.swing.JTextField TF_password;
  246.     private javax.swing.JTextField TF_password2;
  247.     private javax.swing.JTextField TF_username;
  248.     private javax.swing.JLabel jLabel1;
  249.     private javax.swing.JLabel jLabel2;
  250.     private javax.swing.JPanel jPanel2;
  251.     private javax.swing.JLabel lbl_login;
  252.     private javax.swing.JLabel lbl_login_icon;
  253.     // End of variables declaration                  
  254. }
  255.  
Advertisement
Add Comment
Please, Sign In to add comment