Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.30 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.     /** This method is called from within the constructor to
  32.      * initialize the form.
  33.      * WARNING: Do NOT modify this code. The content of this method is
  34.      * always regenerated by the Form Editor.
  35.      */
  36.     @SuppressWarnings("unchecked")
  37.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  38.     private void initComponents() {
  39.  
  40.         jPanel1 = new javax.swing.JPanel();
  41.         jPanel2 = new javax.swing.JPanel();
  42.         jPanel3 = new javax.swing.JPanel();
  43.         jLabel1 = new javax.swing.JLabel();
  44.         jLabel2 = new javax.swing.JLabel();
  45.         jLabel3 = new javax.swing.JLabel();
  46.         jLabel4 = new javax.swing.JLabel();
  47.         jUsername = new javax.swing.JTextField();
  48.         jTipe = new javax.swing.JComboBox();
  49.         jSubmit = new javax.swing.JButton();
  50.         jCancel = new javax.swing.JButton();
  51.         jLabel5 = new javax.swing.JLabel();
  52.         jLabel6 = new javax.swing.JLabel();
  53.         jPassword = new javax.swing.JPasswordField();
  54.  
  55.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  56.         setTitle("Register");
  57.  
  58.         jPanel1.setBackground(new java.awt.Color(102, 255, 51));
  59.  
  60.         jPanel2.setBackground(new java.awt.Color(0, 153, 0));
  61.  
  62.         jLabel1.setFont(new java.awt.Font("Vivaldi", 1, 24)); // NOI18N
  63.         jLabel1.setForeground(new java.awt.Color(0, 153, 102));
  64.         jLabel1.setText("Register");
  65.  
  66.         jLabel2.setText("Username");
  67.  
  68.         jLabel3.setText("Password");
  69.  
  70.         jLabel4.setText("Tipe");
  71.  
  72.         jUsername.setText(" ");
  73.  
  74.         jTipe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "Kasir", "Bos", "Entry" }));
  75.  
  76.         jSubmit.setText("SUBMIT");
  77.         jSubmit.addActionListener(new java.awt.event.ActionListener() {
  78.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  79.                 jSubmitActionPerformed(evt);
  80.             }
  81.         });
  82.  
  83.         jCancel.setText("CANCEL");
  84.         jCancel.addActionListener(new java.awt.event.ActionListener() {
  85.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  86.                 jCancelActionPerformed(evt);
  87.             }
  88.         });
  89.  
  90.         jLabel5.setIcon(new javax.swing.ImageIcon("E:\\Tugas Basis Data\\BookStore\\res\\bookstore.jpg")); // NOI18N
  91.  
  92.         jLabel6.setFont(new java.awt.Font("Comic Sans MS", 3, 12)); // NOI18N
  93.         jLabel6.setForeground(new java.awt.Color(153, 153, 0));
  94.         jLabel6.setText("More Than A Book Store .. ");
  95.  
  96.         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  97.         jPanel3.setLayout(jPanel3Layout);
  98.         jPanel3Layout.setHorizontalGroup(
  99.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100.             .addGroup(jPanel3Layout.createSequentialGroup()
  101.                 .addContainerGap()
  102.                 .addComponent(jLabel5)
  103.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 236, Short.MAX_VALUE)
  104.                 .addComponent(jLabel1)
  105.                 .addGap(29, 29, 29))
  106.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  107.                 .addGap(165, 165, 165)
  108.                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  109.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  110.                         .addComponent(jCancel)
  111.                         .addGap(18, 18, 18)
  112.                         .addComponent(jSubmit))
  113.                     .addGroup(jPanel3Layout.createSequentialGroup()
  114.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  115.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  116.                                 .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
  117.                                 .addGap(30, 30, 30))
  118.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  119.                                 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
  120.                                 .addGap(18, 18, 18))
  121.                             .addGroup(jPanel3Layout.createSequentialGroup()
  122.                                 .addComponent(jLabel2)
  123.                                 .addGap(23, 23, 23)))
  124.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  125.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  126.                             .addComponent(jPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
  127.                             .addComponent(jTipe, javax.swing.GroupLayout.Alignment.TRAILING, 0, 111, Short.MAX_VALUE)
  128.                             .addComponent(jUsername, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))))
  129.                 .addGap(93, 93, 93))
  130.             .addGroup(jPanel3Layout.createSequentialGroup()
  131.                 .addContainerGap()
  132.                 .addComponent(jLabel6)
  133.                 .addContainerGap(268, Short.MAX_VALUE))
  134.         );
  135.         jPanel3Layout.setVerticalGroup(
  136.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  137.             .addGroup(jPanel3Layout.createSequentialGroup()
  138.                 .addContainerGap()
  139.                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  140.                     .addGroup(jPanel3Layout.createSequentialGroup()
  141.                         .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
  142.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  143.                         .addComponent(jLabel6)
  144.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  145.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  146.                             .addComponent(jLabel2)
  147.                             .addComponent(jUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  148.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  149.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  150.                             .addComponent(jLabel3)
  151.                             .addComponent(jPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  152.                         .addGap(12, 12, 12)
  153.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  154.                             .addComponent(jLabel4)
  155.                             .addComponent(jTipe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  156.                         .addGap(13, 13, 13)
  157.                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  158.                             .addComponent(jSubmit)
  159.                             .addComponent(jCancel))
  160.                         .addGap(51, 51, 51))
  161.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  162.                         .addComponent(jLabel1)
  163.                         .addGap(195, 195, 195))))
  164.         );
  165.  
  166.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  167.         jPanel2.setLayout(jPanel2Layout);
  168.         jPanel2Layout.setHorizontalGroup(
  169.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170.             .addGroup(jPanel2Layout.createSequentialGroup()
  171.                 .addContainerGap()
  172.                 .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  173.                 .addContainerGap())
  174.         );
  175.         jPanel2Layout.setVerticalGroup(
  176.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177.             .addGroup(jPanel2Layout.createSequentialGroup()
  178.                 .addContainerGap()
  179.                 .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  180.                 .addContainerGap())
  181.         );
  182.  
  183.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  184.         jPanel1.setLayout(jPanel1Layout);
  185.         jPanel1Layout.setHorizontalGroup(
  186.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  187.             .addGroup(jPanel1Layout.createSequentialGroup()
  188.                 .addContainerGap()
  189.                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  190.                 .addContainerGap())
  191.         );
  192.         jPanel1Layout.setVerticalGroup(
  193.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  194.             .addGroup(jPanel1Layout.createSequentialGroup()
  195.                 .addContainerGap()
  196.                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  197.                 .addContainerGap())
  198.         );
  199.  
  200.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  201.         getContentPane().setLayout(layout);
  202.         layout.setHorizontalGroup(
  203.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  204.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  205.         );
  206.         layout.setVerticalGroup(
  207.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  208.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  209.         );
  210.  
  211.         pack();
  212.     }// </editor-fold>
  213.  
  214.     private void jSubmitActionPerformed(java.awt.event.ActionEvent evt) {
  215.         if (jUsername.getText()==null && jPassword.getPassword()==null){
  216.             JOptionPane.showMessageDialog(null, "Isi Data Anda Dengan Lengkap ! ");
  217.         } else {
  218.             Insert();
  219.         }
  220.  
  221.     }
  222.  
  223.     private void jCancelActionPerformed(java.awt.event.ActionEvent evt) {
  224.         jUsername.setText("");
  225.         jPassword.setText("");
  226.     }
  227.  
  228.     private void Insert(){
  229.         try {
  230.             String username = jUsername.getText();
  231.             String password = new String(jPassword.getPassword());
  232.             String tipe = "";
  233.             switch (jTipe.getSelectedIndex()){
  234.                 case 0 :
  235.                     tipe = "admin";
  236.                     break;
  237.                 case 1 :
  238.                     tipe = "kasir";
  239.                     break;
  240.                 case 2 :
  241.                     tipe = "bos";
  242.                     break;
  243.                 case 3 :
  244.                     tipe = "entry";
  245.                     break;
  246.             }
  247.                
  248.             String sql = "INSERT INTO user (username, password,tipe) VALUES ('" + username + "', '" + password + "', '"+ tipe +"')";
  249.             Koneksi.update(sql);
  250.             jUsername.setText("");
  251.             jPassword.setText("");
  252.         } catch (Exception ex) {
  253.             Logger.getLogger(jRegister.class.getName()).log(Level.SEVERE, null, ex);
  254.             System.out.println(ex.getMessage());
  255.             JOptionPane.showMessageDialog(null, "Maaf, register gagal !");
  256.         }
  257.     }
  258.     /**
  259.     * @param args the command line arguments
  260.     */
  261.     public static void main(String args[]) {
  262.         java.awt.EventQueue.invokeLater(new Runnable() {
  263.             public void run() {
  264.                 new jRegister().setVisible(true);
  265.             }
  266.         });
  267.     }
  268.  
  269.     // Variables declaration - do not modify
  270.     private javax.swing.JButton jCancel;
  271.     private javax.swing.JLabel jLabel1;
  272.     private javax.swing.JLabel jLabel2;
  273.     private javax.swing.JLabel jLabel3;
  274.     private javax.swing.JLabel jLabel4;
  275.     private javax.swing.JLabel jLabel5;
  276.     private javax.swing.JLabel jLabel6;
  277.     private javax.swing.JPanel jPanel1;
  278.     private javax.swing.JPanel jPanel2;
  279.     private javax.swing.JPanel jPanel3;
  280.     private javax.swing.JPasswordField jPassword;
  281.     private javax.swing.JButton jSubmit;
  282.     private javax.swing.JComboBox jTipe;
  283.     private javax.swing.JTextField jUsername;
  284.     // End of variables declaration
  285.  
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement