Advertisement
Guest User

RegisterForm & MenuForm

a guest
Jun 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.20 KB | None | 0 0
  1. [RegisterForm]
  2. import java.awt.FlowLayout;
  3. import java.awt.GridLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.MouseListener;
  8. import java.sql.SQLException;
  9. import java.util.Vector;
  10.  
  11. import javax.swing.ButtonGroup;
  12. import javax.swing.ImageIcon;
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JOptionPane;
  17. import javax.swing.JPanel;
  18. import javax.swing.JPasswordField;
  19. import javax.swing.JRadioButton;
  20. import javax.swing.JTextField;
  21. import javax.swing.table.DefaultTableModel;
  22.  
  23.  
  24. public class RegisterForm extends JFrame implements ActionListener{
  25.  
  26. JPanel paneljudul = new JPanel(new FlowLayout());
  27. JPanel panelbutton = new JPanel(new GridLayout(2,1));
  28. JPanel paneltengah = new JPanel(new GridLayout(2, 1));
  29. JPanel panelform = new JPanel(new GridLayout(8, 2));
  30. JPanel panelgender = new JPanel(new GridLayout(1, 2));
  31.  
  32. JLabel title = new JLabel("Register");
  33. private JTextField txtid;
  34. JTextField txtname = new JTextField();
  35. JTextField txtuser = new JTextField();
  36. JTextField txtemail = new JTextField();
  37. JTextField txtphone = new JTextField();
  38. JTextField txtaddress = new JTextField();
  39. JPasswordField txtpass = new JPasswordField();
  40. JRadioButton female = new JRadioButton("Female");
  41. JRadioButton male = new JRadioButton("Male");
  42. ButtonGroup bg = new ButtonGroup();
  43. JButton insert = new JButton("Insert");
  44. JButton cancel = new JButton("Cancel");
  45.  
  46. Connect con = new Connect();
  47.  
  48. public void AutoIDUser() {
  49. try {
  50. con.rs = con.st.executeQuery("select count(UserID) from MsUser");
  51. con.rs.next();
  52. int JumlahData = con.rs.getInt(1);
  53. if (JumlahData == 0){
  54. txtid.setText("U001");
  55. }
  56. else if (JumlahData < 9) {
  57. con.rs = con.st.executeQuery("select max(UserID) from MsUser");
  58. while (con.rs.next()){
  59. String UserID = con.rs.getString(1);
  60. String AngkaUserID = UserID.substring(3,4);
  61. int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
  62. txtid.setText(String.valueOf("U00"+UserIDBaru));
  63. }
  64. }
  65. else if (JumlahData < 99) {
  66. con.rs = con.st.executeQuery("select max(UserID) from MsUser");
  67. while (con.rs.next()){
  68. String UserID = con.rs.getString(1);
  69. String AngkaUserID = UserID.substring(2,4);
  70. int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
  71. txtid.setText(String.valueOf("U0"+UserIDBaru));
  72. }
  73. }
  74. else if (JumlahData >= 99) {
  75. con.rs = con.st.executeQuery("select max(UserID) from MsUser");
  76. while (con.rs.next()){
  77. String UserID = con.rs.getString(1);
  78. String AngkaUserID = UserID.substring(1,4);
  79. int UserIDBaru = Integer.parseInt(AngkaUserID)+1;
  80. txtid.setText(String.valueOf("U"+UserIDBaru));
  81. }
  82. }
  83. } catch (SQLException e) {
  84. e.printStackTrace();
  85. }
  86. }
  87.  
  88. public void setUI(){
  89.  
  90. paneljudul.add(title);
  91. add(paneljudul, "North");
  92.  
  93. paneltengah.add(panelform);
  94. add(paneltengah, "Center");
  95.  
  96. panelgender.add(male);
  97. panelgender.add(female);
  98. bg.add(male);
  99. bg.add(female);
  100.  
  101. panelform.add(new JLabel("User ID"));
  102. panelform.add(txtid); txtid.setEnabled(false);
  103. panelform.add(new JLabel("Username"));
  104. panelform.add(txtuser);
  105. panelform.add(new JLabel("Password"));
  106. panelform.add(txtpass);
  107. panelform.add(new JLabel("Name"));
  108. panelform.add(txtname);
  109. panelform.add(new JLabel("Email"));
  110. panelform.add(txtemail);
  111. panelform.add(new JLabel("Phone Number"));
  112. panelform.add(txtphone);
  113. panelform.add(new JLabel("Address"));
  114. panelform.add(txtaddress);
  115. panelform.add(new JLabel("Gender"));
  116. panelform.add(panelgender);
  117.  
  118. panelbutton.add(insert);
  119. panelbutton.add(cancel);
  120. add(panelbutton, "South");
  121.  
  122. // INI DIGANTI
  123.  
  124. //table.addMouseListener(this);
  125. // SET ACTION LISTENER
  126. insert.addActionListener(this);
  127. cancel.addActionListener(this);
  128. // END SET ACTION LISTENER
  129.  
  130.  
  131. }
  132.  
  133. public RegisterForm() {
  134. setUI();
  135. setSize(450, 500);
  136. setLocationRelativeTo(null);
  137. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  138. setVisible(true);
  139. AutoIDUser();
  140. }
  141.  
  142. @Override
  143. public void actionPerformed(ActionEvent e) {
  144. if(e.getSource() == insert){
  145. String userid = txtid.getText();
  146. String userfullname = txtname.getText();
  147. String username = txtuser.getText();
  148. String useremail = txtemail.getText();
  149. String userphone = txtphone.getText();
  150. String useraddress = txtaddress.getText();
  151. String userpass = txtpass.getText();
  152. String usergender;
  153. if(male.isSelected()==true){
  154. usergender = "Male";
  155. }
  156. else{
  157. usergender = "Female";
  158. }
  159. if(txtuser.getText().equals("")){
  160. JOptionPane.showMessageDialog(null, "USERNAME is blank");
  161. txtuser.requestFocus();
  162. }else if(username.length() > 15 || username.length() < 5 ) {
  163. JOptionPane.showMessageDialog(null,"Username length must be between 5 and 15 characters.","Information",JOptionPane.INFORMATION_MESSAGE);
  164. txtuser.requestFocus(true);
  165. }else if(txtemail.getText().equals("")){
  166. JOptionPane.showMessageDialog(null, "EMAIL is blank");
  167. txtemail.requestFocus();
  168. }else if(txtname.getText().equals("")){
  169. JOptionPane.showMessageDialog(null, "NAME is blank");
  170. txtname.requestFocus();
  171. }else if(txtpass.getText().equals("")){
  172. JOptionPane.showMessageDialog(null, "PASSWORD is blank");
  173. txtpass.requestFocus();
  174. }else if(userpass.length() > 15 || userpass.length() < 5 ) {
  175. JOptionPane.showMessageDialog(null,"Password length must be between 5 and 15 characters.","Information",JOptionPane.INFORMATION_MESSAGE);
  176. txtpass.requestFocus(true);
  177. }else if(txtaddress.getText().equals("")){
  178. JOptionPane.showMessageDialog(null, "ADDRESS is blank");
  179. txtaddress.requestFocus();
  180. }else if(txtphone.getText().equals("")){
  181. JOptionPane.showMessageDialog(null, "PHONE is blank");
  182. txtphone.requestFocus();
  183. }else{
  184. con.executeInsertUser(username, userpass, userfullname, useremail, userphone, useraddress, usergender);
  185. JOptionPane.showMessageDialog(null, "Input Success");
  186. new MainForm();
  187. this.dispose();
  188. }
  189. }else if(e.getSource() == cancel){
  190. new MenuForm();
  191. this.dispose();
  192. }
  193. }
  194. }
  195.  
  196. [MenuForm]
  197. import java.awt.Color;
  198. import java.awt.Component;
  199. import java.awt.FlowLayout;
  200. import java.awt.Font;
  201. import java.awt.GridLayout;
  202. import java.awt.event.ActionEvent;
  203. import java.awt.event.ActionListener;
  204.  
  205. import javax.swing.ImageIcon;
  206. import javax.swing.JButton;
  207. import javax.swing.JDesktopPane;
  208. import javax.swing.JFrame;
  209. import javax.swing.JLabel;
  210. import javax.swing.JOptionPane;
  211. import javax.swing.JPanel;
  212. import javax.swing.JPasswordField;
  213. import javax.swing.JTextField;
  214.  
  215.  
  216. public class MenuForm extends JFrame implements ActionListener{
  217. JPanel panellogin = new JPanel(new GridLayout(2,2, 10,10));
  218. JPanel panelbutton = new JPanel(new GridLayout(2,1));
  219. JTextField txtuser = new JTextField();
  220. JPasswordField txtpass = new JPasswordField();
  221. JButton login = new JButton("Login");
  222. JButton register = new JButton("Register");
  223. JDesktopPane pane = new JDesktopPane();
  224.  
  225. public void setUI(){
  226. JLabel image = new JLabel("");
  227. ImageIcon icon = new ImageIcon("images/bluejack.jpg");
  228. image.setIcon(icon);
  229.  
  230. add(image, "North");
  231.  
  232. panelbutton.add(login);
  233. panelbutton.add(register);
  234. add(panelbutton, "South");
  235. login.addActionListener(this);
  236. register.addActionListener(this);
  237.  
  238. add(new JLabel(" "), "West");
  239. add(new JLabel(" "), "East");
  240. }
  241.  
  242. public MenuForm() {
  243. setUI();
  244. setTitle("Bluejack Boutique");
  245. setSize(300, 220); // setSize(w, h);
  246. setLocationRelativeTo(null);
  247. setDefaultCloseOperation(EXIT_ON_CLOSE);
  248. setVisible(true);
  249. }
  250.  
  251. @Override
  252. public void actionPerformed(ActionEvent e) {
  253. if(e.getSource() == login){
  254. //LoginForm login = new LoginForm();
  255. new LoginForm();
  256. this.dispose();
  257. }else if(e.getSource() == register){
  258. new RegisterForm();
  259. this.dispose();
  260. //JOptionPane.showMessageDialog(null, "Username dan Password SALAH");
  261. }
  262.  
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement