Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [RegisterForm]
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.sql.SQLException;
- import java.util.Vector;
- import javax.swing.ButtonGroup;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- import javax.swing.table.DefaultTableModel;
- public class RegisterForm extends JFrame implements ActionListener{
- JPanel paneljudul = new JPanel(new FlowLayout());
- JPanel panelbutton = new JPanel(new GridLayout(2,1));
- JPanel paneltengah = new JPanel(new GridLayout(2, 1));
- JPanel panelform = new JPanel(new GridLayout(8, 2));
- JPanel panelgender = new JPanel(new GridLayout(1, 2));
- JLabel title = new JLabel("Register");
- private JTextField txtid;
- JTextField txtname = new JTextField();
- JTextField txtuser = new JTextField();
- JTextField txtemail = new JTextField();
- JTextField txtphone = new JTextField();
- JTextField txtaddress = new JTextField();
- JPasswordField txtpass = new JPasswordField();
- JRadioButton female = new JRadioButton("Female");
- JRadioButton male = new JRadioButton("Male");
- ButtonGroup bg = new ButtonGroup();
- JButton insert = new JButton("Insert");
- JButton cancel = new JButton("Cancel");
- Connect con = new Connect();
- public void AutoIDUser() {
- try {
- con.rs = con.st.executeQuery("select count(UserID) from MsUser");
- con.rs.next();
- int JumlahData = con.rs.getInt(1);
- if (JumlahData == 0){
- txtid.setText("U001");
- }
- else if (JumlahData < 9) {
- con.rs = con.st.executeQuery("select max(UserID) from MsUser");
- while (con.rs.next()){
- String UserID = con.rs.getString(1);
- String AngkaUserID = UserID.substring(3,4);
- int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
- txtid.setText(String.valueOf("U00"+UserIDBaru));
- }
- }
- else if (JumlahData < 99) {
- con.rs = con.st.executeQuery("select max(UserID) from MsUser");
- while (con.rs.next()){
- String UserID = con.rs.getString(1);
- String AngkaUserID = UserID.substring(2,4);
- int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
- txtid.setText(String.valueOf("U0"+UserIDBaru));
- }
- }
- else if (JumlahData >= 99) {
- con.rs = con.st.executeQuery("select max(UserID) from MsUser");
- while (con.rs.next()){
- String UserID = con.rs.getString(1);
- String AngkaUserID = UserID.substring(1,4);
- int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
- txtid.setText(String.valueOf("U"+UserIDBaru));
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void setUI(){
- paneljudul.add(title);
- add(paneljudul, "North");
- paneltengah.add(panelform);
- add(paneltengah, "Center");
- panelgender.add(male);
- panelgender.add(female);
- bg.add(male);
- bg.add(female);
- panelform.add(new JLabel("User ID"));
- panelform.add(txtid); txtid.setEnabled(false);
- panelform.add(new JLabel("Username"));
- panelform.add(txtuser);
- panelform.add(new JLabel("Password"));
- panelform.add(txtpass);
- panelform.add(new JLabel("Name"));
- panelform.add(txtname);
- panelform.add(new JLabel("Email"));
- panelform.add(txtemail);
- panelform.add(new JLabel("Phone Number"));
- panelform.add(txtphone);
- panelform.add(new JLabel("Address"));
- panelform.add(txtaddress);
- panelform.add(new JLabel("Gender"));
- panelform.add(panelgender);
- panelbutton.add(insert);
- panelbutton.add(cancel);
- add(panelbutton, "South");
- // INI DIGANTI
- //table.addMouseListener(this);
- // SET ACTION LISTENER
- insert.addActionListener(this);
- cancel.addActionListener(this);
- // END SET ACTION LISTENER
- }
- public RegisterForm() {
- setUI();
- setSize(450, 500);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- setVisible(true);
- AutoIDUser();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == insert){
- String userid = txtid.getText();
- String userfullname = txtname.getText();
- String username = txtuser.getText();
- String useremail = txtemail.getText();
- String userphone = txtphone.getText();
- String useraddress = txtaddress.getText();
- String userpass = txtpass.getText();
- String usergender;
- if(male.isSelected()==true){
- usergender = "Male";
- }
- else{
- usergender = "Female";
- }
- if(txtuser.getText().equals("")){
- JOptionPane.showMessageDialog(null, "USERNAME is blank");
- txtuser.requestFocus();
- }else if(username.length() > 15 || username.length() < 5 ) {
- JOptionPane.showMessageDialog(null,"Username length must be between 5 and 15 characters.","Information",JOptionPane.INFORMATION_MESSAGE);
- txtuser.requestFocus(true);
- }else if(txtemail.getText().equals("")){
- JOptionPane.showMessageDialog(null, "EMAIL is blank");
- txtemail.requestFocus();
- }else if(txtname.getText().equals("")){
- JOptionPane.showMessageDialog(null, "NAME is blank");
- txtname.requestFocus();
- }else if(txtpass.getText().equals("")){
- JOptionPane.showMessageDialog(null, "PASSWORD is blank");
- txtpass.requestFocus();
- }else if(userpass.length() > 15 || userpass.length() < 5 ) {
- JOptionPane.showMessageDialog(null,"Password length must be between 5 and 15 characters.","Information",JOptionPane.INFORMATION_MESSAGE);
- txtpass.requestFocus(true);
- }else if(txtaddress.getText().equals("")){
- JOptionPane.showMessageDialog(null, "ADDRESS is blank");
- txtaddress.requestFocus();
- }else if(txtphone.getText().equals("")){
- JOptionPane.showMessageDialog(null, "PHONE is blank");
- txtphone.requestFocus();
- }else{
- con.executeInsertUser(username, userpass, userfullname, useremail, userphone, useraddress, usergender);
- JOptionPane.showMessageDialog(null, "Input Success");
- new MainForm();
- this.dispose();
- }
- }else if(e.getSource() == cancel){
- new MenuForm();
- this.dispose();
- }
- }
- }
- [MenuForm]
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JDesktopPane;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- public class MenuForm extends JFrame implements ActionListener{
- JPanel panellogin = new JPanel(new GridLayout(2,2, 10,10));
- JPanel panelbutton = new JPanel(new GridLayout(2,1));
- JTextField txtuser = new JTextField();
- JPasswordField txtpass = new JPasswordField();
- JButton login = new JButton("Login");
- JButton register = new JButton("Register");
- JDesktopPane pane = new JDesktopPane();
- public void setUI(){
- JLabel image = new JLabel("");
- ImageIcon icon = new ImageIcon("images/bluejack.jpg");
- image.setIcon(icon);
- add(image, "North");
- panelbutton.add(login);
- panelbutton.add(register);
- add(panelbutton, "South");
- login.addActionListener(this);
- register.addActionListener(this);
- add(new JLabel(" "), "West");
- add(new JLabel(" "), "East");
- }
- public MenuForm() {
- setUI();
- setTitle("Bluejack Boutique");
- setSize(300, 220); // setSize(w, h);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == login){
- //LoginForm login = new LoginForm();
- new LoginForm();
- this.dispose();
- }else if(e.getSource() == register){
- new RegisterForm();
- this.dispose();
- //JOptionPane.showMessageDialog(null, "Username dan Password SALAH");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement