Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * jRegister.java
  8.  *
  9.  * Created on 06 Mei 10, 7:33:53
  10.  */
  11.  
  12. package form;
  13.  
  14. import db.Koneksi;
  15. import java.sql.ResultSet;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. import javax.swing.JOptionPane;
  19.  
  20. /**
  21.  *
  22.  * @author Lenovo
  23.  */
  24. public class jRegister extends javax.swing.JFrame {
  25.  
  26.     /** Creates new form jRegister */
  27.     public jRegister() {
  28.         initComponents();
  29.     }
  30.  
  31.     private void jSubmitActionPerformed(java.awt.event.ActionEvent evt) {
  32.         if (jUsername.getText()==null && jPassword.getPassword()==null){
  33.             JOptionPane.showMessageDialog(null, "Isi Data Anda Dengan Lengkap ! ");
  34.         } else {
  35.             Insert();
  36.         }
  37.  
  38.     }
  39.  
  40.     private void jCancelActionPerformed(java.awt.event.ActionEvent evt) {
  41.         jUsername.setText("");
  42.         jPassword.setText("");
  43.     }
  44.  
  45.     private void Insert(){
  46.         try {
  47.             String username = jUsername.getText();
  48.             String password = new String(jPassword.getPassword());
  49.             String tipe = "";
  50.             switch (jTipe.getSelectedIndex()){
  51.                 case 0 :
  52.                     tipe = "admin";
  53.                     break;
  54.                 case 1 :
  55.                     tipe = "kasir";
  56.                     break;
  57.                 case 2 :
  58.                     tipe = "bos";
  59.                     break;
  60.                 case 3 :
  61.                     tipe = "entry";
  62.                     break;
  63.             }
  64.                
  65.             String sql = "INSERT INTO user (username, password,tipe) VALUES ('" + username + "', '" + password + "', '"+ tipe +"')";
  66.             ResultSet query = Koneksi.execute(sql);
  67.            
  68.         } catch (Exception ex) {
  69.             Logger.getLogger(jRegister.class.getName()).log(Level.SEVERE, null, ex);
  70.             System.out.println(ex.getMessage());
  71.             JOptionPane.showMessageDialog(null, "Maaf, register gagal !");
  72.         }
  73.     }
  74.     /**
  75.     * @param args the command line arguments
  76.     */
  77.     public static void main(String args[]) {
  78.         java.awt.EventQueue.invokeLater(new Runnable() {
  79.             public void run() {
  80.                 new jRegister().setVisible(true);
  81.             }
  82.         });
  83.     }
  84.  
  85.     // Variables declaration - do not modify
  86.     private javax.swing.JButton jCancel;
  87.     private javax.swing.JLabel jLabel1;
  88.     private javax.swing.JLabel jLabel2;
  89.     private javax.swing.JLabel jLabel3;
  90.     private javax.swing.JLabel jLabel4;
  91.     private javax.swing.JLabel jLabel5;
  92.     private javax.swing.JLabel jLabel6;
  93.     private javax.swing.JPanel jPanel1;
  94.     private javax.swing.JPanel jPanel2;
  95.     private javax.swing.JPanel jPanel3;
  96.     private javax.swing.JPasswordField jPassword;
  97.     private javax.swing.JButton jSubmit;
  98.     private javax.swing.JComboBox jTipe;
  99.     private javax.swing.JTextField jUsername;
  100.     // End of variables declaration
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement