Advertisement
Guest User

Untitled

a guest
Mar 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.77 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLDataException;
  8.  
  9. /**
  10. *
  11. * @author l14y07w25
  12. */
  13. public class CreateAcc extends javax.swing.JFrame {
  14. String username;
  15. String password;
  16. String famname;
  17. String mobileno;
  18. String email;
  19. String staddress;
  20.  
  21. static final String JDBC_DRIVER ="com.mysql.jdbc.Driver";
  22. static final String DB_URL = "jdbc:mysql://localhost:3306/f.clothes for rent?zeroDateTimeBehavior=convertToNull";
  23. static final String USER = "root";
  24. static final String PASS = "";
  25. String sql;
  26. Connection con;
  27. Statement state;
  28. /**
  29. * Creates new form CreateAccountMenu
  30. */
  31. public CreateAcc() {
  32. initComponents();
  33. }
  34.  
  35. /**
  36. * This method is called from within the constructor to initialize the form.
  37. * WARNING: Do NOT modify this code. The content of this method is always
  38. * regenerated by the Form Editor.
  39. */
  40. @SuppressWarnings("unchecked")
  41. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  42. private void initComponents() {
  43.  
  44. jLabel1 = new javax.swing.JLabel();
  45. jLabel2 = new javax.swing.JLabel();
  46. jLabel3 = new javax.swing.JLabel();
  47. jLabel4 = new javax.swing.JLabel();
  48. jfamname = new javax.swing.JTextField();
  49. jusername = new javax.swing.JTextField();
  50. jButton1 = new javax.swing.JButton();
  51. jLabel7 = new javax.swing.JLabel();
  52. jstaddress = new javax.swing.JTextField();
  53. jmobileno = new javax.swing.JTextField();
  54. jLabel8 = new javax.swing.JLabel();
  55. jLabel5 = new javax.swing.JLabel();
  56. jemail = new javax.swing.JTextField();
  57. jLabel6 = new javax.swing.JLabel();
  58. jpass = new javax.swing.JTextField();
  59.  
  60. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  61.  
  62. jLabel1.setText("Username");
  63.  
  64. jLabel2.setText("Last name");
  65.  
  66. jLabel3.setText("First name");
  67.  
  68. jLabel4.setText("Middle name");
  69.  
  70. jfamname.addActionListener(new java.awt.event.ActionListener() {
  71. public void actionPerformed(java.awt.event.ActionEvent evt) {
  72. jfamnameActionPerformed(evt);
  73. }
  74. });
  75.  
  76. jusername.addActionListener(new java.awt.event.ActionListener() {
  77. public void actionPerformed(java.awt.event.ActionEvent evt) {
  78. jusernameActionPerformed(evt);
  79. }
  80. });
  81.  
  82. jButton1.setText("Create");
  83. jButton1.addActionListener(new java.awt.event.ActionListener() {
  84. public void actionPerformed(java.awt.event.ActionEvent evt) {
  85. jButton1ActionPerformed(evt);
  86. }
  87. });
  88.  
  89. jLabel7.setText("Address");
  90.  
  91. jLabel8.setText("Mobile No.\n");
  92.  
  93. jLabel5.setText("Email Address\n");
  94.  
  95. jLabel6.setText("Password");
  96.  
  97. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  98. getContentPane().setLayout(layout);
  99. layout.setHorizontalGroup(
  100. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  101. .addGroup(layout.createSequentialGroup()
  102. .addGap(26, 26, 26)
  103. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  106. .addComponent(jstaddress, javax.swing.GroupLayout.Alignment.LEADING)
  107. .addGroup(layout.createSequentialGroup()
  108. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  109. .addComponent(jusername, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
  110. .addComponent(jLabel1)
  111. .addComponent(jLabel2))
  112. .addGap(18, 45, Short.MAX_VALUE)
  113. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114. .addGroup(layout.createSequentialGroup()
  115. .addComponent(jLabel3)
  116. .addGap(70, 70, 70)
  117. .addComponent(jLabel4))
  118. .addComponent(jLabel6)
  119. .addComponent(jpass, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
  120. .addGap(27, 27, 27))
  121. .addComponent(jfamname, javax.swing.GroupLayout.Alignment.LEADING))
  122. .addGap(46, 46, 46))
  123. .addGroup(layout.createSequentialGroup()
  124. .addComponent(jLabel5)
  125. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  126. .addGroup(layout.createSequentialGroup()
  127. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  128. .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
  129. .addComponent(jLabel8)
  130. .addComponent(jmobileno, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
  131. .addComponent(jemail, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
  132. .addGap(0, 0, Short.MAX_VALUE))))
  133. .addGroup(layout.createSequentialGroup()
  134. .addGap(132, 132, 132)
  135. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
  136. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  137. );
  138. layout.setVerticalGroup(
  139. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  140. .addGroup(layout.createSequentialGroup()
  141. .addContainerGap()
  142. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  143. .addComponent(jLabel1)
  144. .addComponent(jLabel6))
  145. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  146. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  147. .addComponent(jusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  148. .addComponent(jpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  149. .addGap(22, 22, 22)
  150. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  151. .addComponent(jLabel2)
  152. .addComponent(jLabel3)
  153. .addComponent(jLabel4))
  154. .addGap(18, 18, 18)
  155. .addComponent(jfamname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  156. .addGap(18, 18, 18)
  157. .addComponent(jLabel8)
  158. .addGap(4, 4, 4)
  159. .addComponent(jmobileno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  160. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  161. .addComponent(jLabel5)
  162. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  163. .addComponent(jemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  164. .addGap(18, 18, 18)
  165. .addComponent(jLabel7)
  166. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  167. .addComponent(jstaddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  168. .addGap(38, 38, 38)
  169. .addComponent(jButton1)
  170. .addContainerGap(29, Short.MAX_VALUE))
  171. );
  172.  
  173. pack();
  174. }// </editor-fold>
  175.  
  176. private void jfamnameActionPerformed(java.awt.event.ActionEvent evt) {
  177. // TODO add your handling code here:
  178. }
  179.  
  180. private void jusernameActionPerformed(java.awt.event.ActionEvent evt) {
  181. // TODO add your handling code here:
  182. }
  183.  
  184. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  185. // TODO add your handling code here:
  186. username = jusername.getText();
  187. password = jpass.getText();
  188. famname = jfamname.getText();
  189. mobileno = jmobileno.getText();
  190. email = jemail.getText();
  191. staddress = jstaddress.getText();
  192.  
  193. try{
  194. Class.forName(JDBC_DRIVER);
  195. con = DriverManager.getConnection(DB_URL,USER,PASS);
  196. state = con.createStatement();
  197.  
  198. sql = "insert into create values('"+jusername.getText+"','"+jpass.getText+"','"+jfamname.getText+"','"+jmobileno.getText+"','"+jemail.getText+"','"+jstaddress.getText+"') ";
  199. state.executeUpdate(sql);
  200. JOptionPane.showMessageDialog(null,"Welcome !!!");
  201. LoginMenu log = new LoginMenu();
  202. log.setVisible(true);
  203. this.setVisible(false);
  204.  
  205. } catch(Exception e){
  206. JOptionPane.showMessageDialog(null, e.toString());
  207. }
  208. }
  209.  
  210. /**
  211. * @param args the command line arguments
  212. */
  213. public static void main(String args[]) {
  214. /* Set the Nimbus look and feel */
  215. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  216. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  217. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  218. */
  219. try {
  220. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  221. if ("Nimbus".equals(info.getName())) {
  222. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  223. break;
  224. }
  225. }
  226. } catch (ClassNotFoundException ex) {
  227. java.util.logging.Logger.getLogger(CreateAcc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  228. } catch (InstantiationException ex) {
  229. java.util.logging.Logger.getLogger(CreateAcc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  230. } catch (IllegalAccessException ex) {
  231. java.util.logging.Logger.getLogger(CreateAcc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  232. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  233. java.util.logging.Logger.getLogger(CreateAcc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  234. }
  235. //</editor-fold>
  236. //</editor-fold>
  237.  
  238. /* Create and display the form */
  239. java.awt.EventQueue.invokeLater(new Runnable() {
  240. public void run() {
  241. new CreateAcc().setVisible(true);
  242. }
  243. });
  244. }
  245.  
  246. // Variables declaration - do not modify
  247. private javax.swing.JButton jButton1;
  248. private javax.swing.JLabel jLabel1;
  249. private javax.swing.JLabel jLabel2;
  250. private javax.swing.JLabel jLabel3;
  251. private javax.swing.JLabel jLabel4;
  252. private javax.swing.JLabel jLabel5;
  253. private javax.swing.JLabel jLabel6;
  254. private javax.swing.JLabel jLabel7;
  255. private javax.swing.JLabel jLabel8;
  256. private javax.swing.JTextField jemail;
  257. private javax.swing.JTextField jfamname;
  258. private javax.swing.JTextField jmobileno;
  259. private javax.swing.JTextField jpass;
  260. private javax.swing.JTextField jstaddress;
  261. private javax.swing.JTextField jusername;
  262. // End of variables declaration
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement