Advertisement
Guest User

Untitled

a guest
Mar 8th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.95 KB | None | 0 0
  1. //Allows for customers to edit their own details
  2. public class EditCustomer extends javax.swing.JFrame {
  3. Customer LoggedInCustomer;
  4.  
  5. public EditCustomer(Customer customer) {
  6. LoggedInCustomer = customer;
  7. initComponents();
  8.  
  9. txtUsername.setText(LoggedInCustomer.getUsername());
  10. txtPassword.setText(LoggedInCustomer.getPassword());
  11. txtFirstName.setText(LoggedInCustomer.getFirstName());
  12. txtLastName.setText(LoggedInCustomer.getLastName());
  13. txtHouseNo.setText(LoggedInCustomer.getAddressLine1());
  14. txtStreet.setText(LoggedInCustomer.getAddressLine2());
  15. txtTown.setText(LoggedInCustomer.getTown());
  16. txtPostcode.setText(LoggedInCustomer.getPostcode());
  17. }
  18.  
  19. /**
  20. * This method is called from within the constructor to initialize the form.
  21. * WARNING: Do NOT modify this code. The content of this method is always
  22. * regenerated by the Form Editor.
  23. */
  24. @SuppressWarnings("unchecked")
  25. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  26. private void initComponents() {
  27.  
  28. jLabel1 = new javax.swing.JLabel();
  29. btnBack = new javax.swing.JButton();
  30. jLabel2 = new javax.swing.JLabel();
  31. txtUsername = new javax.swing.JTextField();
  32. jLabel3 = new javax.swing.JLabel();
  33. txtPassword = new javax.swing.JTextField();
  34. jLabel4 = new javax.swing.JLabel();
  35. txtFirstName = new javax.swing.JTextField();
  36. jLabel5 = new javax.swing.JLabel();
  37. txtLastName = new javax.swing.JTextField();
  38. jLabel6 = new javax.swing.JLabel();
  39. jLabel7 = new javax.swing.JLabel();
  40. txtHouseNo = new javax.swing.JTextField();
  41. jLabel8 = new javax.swing.JLabel();
  42. txtStreet = new javax.swing.JTextField();
  43. jLabel9 = new javax.swing.JLabel();
  44. txtTown = new javax.swing.JTextField();
  45. jLabel10 = new javax.swing.JLabel();
  46. txtPostcode = new javax.swing.JTextField();
  47. btnSubmit = new javax.swing.JButton();
  48. btnUndo = new javax.swing.JButton();
  49. lblError = new javax.swing.JLabel();
  50.  
  51. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  52.  
  53. jLabel1.setText("EDIT MY DETAILS");
  54.  
  55. btnBack.setText("BACK");
  56. btnBack.addActionListener(new java.awt.event.ActionListener() {
  57. public void actionPerformed(java.awt.event.ActionEvent evt) {
  58. btnBackActionPerformed(evt);
  59. }
  60. });
  61.  
  62. jLabel2.setText("Username:");
  63.  
  64. jLabel3.setText("Password:");
  65.  
  66. jLabel4.setText("First Name:");
  67.  
  68. jLabel5.setText("Last Name:");
  69.  
  70. jLabel6.setText("Address -");
  71.  
  72. jLabel7.setText("House/Flat Number:");
  73.  
  74. jLabel8.setText("Street:");
  75.  
  76. jLabel9.setText("Town:");
  77.  
  78. jLabel10.setText("Postcode:");
  79.  
  80. btnSubmit.setText("SUBMIT");
  81. btnSubmit.addActionListener(new java.awt.event.ActionListener() {
  82. public void actionPerformed(java.awt.event.ActionEvent evt) {
  83. btnSubmitActionPerformed(evt);
  84. }
  85. });
  86.  
  87. btnUndo.setText("UNDO CHANGES");
  88. btnUndo.addActionListener(new java.awt.event.ActionListener() {
  89. public void actionPerformed(java.awt.event.ActionEvent evt) {
  90. btnUndoActionPerformed(evt);
  91. }
  92. });
  93.  
  94. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  95. getContentPane().setLayout(layout);
  96. layout.setHorizontalGroup(
  97. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98. .addGroup(layout.createSequentialGroup()
  99. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  101. .addGroup(layout.createSequentialGroup()
  102. .addContainerGap()
  103. .addComponent(btnBack)
  104. .addGap(65, 65, 65)
  105. .addComponent(jLabel1))
  106. .addGroup(layout.createSequentialGroup()
  107. .addGap(73, 73, 73)
  108. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  109. .addGroup(layout.createSequentialGroup()
  110. .addComponent(jLabel3)
  111. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  112. .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
  113. .addGroup(layout.createSequentialGroup()
  114. .addComponent(jLabel2)
  115. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  116. .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))))
  117. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  118. .addContainerGap()
  119. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  120. .addGroup(layout.createSequentialGroup()
  121. .addComponent(jLabel5)
  122. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  123. .addComponent(txtLastName))
  124. .addGroup(layout.createSequentialGroup()
  125. .addComponent(jLabel4)
  126. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  127. .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))))
  128. .addGroup(layout.createSequentialGroup()
  129. .addGap(169, 169, 169)
  130. .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
  131. .addGroup(layout.createSequentialGroup()
  132. .addGap(41, 41, 41)
  133. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  134. .addComponent(jLabel8)
  135. .addComponent(jLabel7)
  136. .addComponent(jLabel9)
  137. .addComponent(jLabel10))
  138. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  139. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  140. .addComponent(txtHouseNo)
  141. .addComponent(txtStreet)
  142. .addComponent(txtTown)
  143. .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))))
  144. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  145. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  146. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  147. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  148. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  149. .addComponent(btnUndo)
  150. .addGap(131, 131, 131))
  151. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  152. .addComponent(btnSubmit)
  153. .addGap(153, 153, 153))))
  154. .addGroup(layout.createSequentialGroup()
  155. .addGap(65, 65, 65)
  156. .addComponent(lblError, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
  157. .addGap(0, 67, Short.MAX_VALUE))
  158. );
  159. layout.setVerticalGroup(
  160. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  161. .addGroup(layout.createSequentialGroup()
  162. .addGap(17, 17, 17)
  163. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  164. .addComponent(jLabel1)
  165. .addComponent(btnBack))
  166. .addGap(18, 18, 18)
  167. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  168. .addComponent(jLabel2)
  169. .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  170. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  171. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  172. .addComponent(jLabel3)
  173. .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  174. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  175. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  176. .addComponent(jLabel4)
  177. .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  178. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  179. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  180. .addComponent(jLabel5)
  181. .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  182. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  183. .addComponent(jLabel6)
  184. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  185. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  186. .addComponent(jLabel7)
  187. .addComponent(txtHouseNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  188. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  189. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  190. .addComponent(jLabel8)
  191. .addComponent(txtStreet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  192. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  193. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  194. .addComponent(jLabel9)
  195. .addComponent(txtTown, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  196. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  197. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  198. .addComponent(jLabel10)
  199. .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  200. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  201. .addComponent(lblError, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
  202. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  203. .addComponent(btnSubmit)
  204. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  205. .addComponent(btnUndo)
  206. .addContainerGap())
  207. );
  208.  
  209. pack();
  210. }// </editor-fold>
  211.  
  212. //When the back button is pressed, the user is taken back to the CustomerHome page
  213. private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  214. CustomerHome customerHome = new CustomerHome(LoggedInCustomer);
  215. this.dispose();
  216. customerHome.setVisible(true);
  217. }
  218.  
  219. //When the Undo button is pressed, the user's data that's stored in the database appears in the textboxes
  220. private void btnUndoActionPerformed(java.awt.event.ActionEvent evt) {
  221. txtUsername.setText(LoggedInCustomer.getUsername());
  222. txtPassword.setText(LoggedInCustomer.getPassword());
  223. txtFirstName.setText(LoggedInCustomer.getFirstName());
  224. txtLastName.setText(LoggedInCustomer.getLastName());
  225. txtHouseNo.setText(LoggedInCustomer.getAddressLine1());
  226. txtStreet.setText(LoggedInCustomer.getAddressLine2());
  227. txtTown.setText(LoggedInCustomer.getTown());
  228. txtPostcode.setText(LoggedInCustomer.getPostcode());
  229.  
  230. lblError.setText("");
  231. }
  232.  
  233. //When the Submit button is pressed, the user's data is updated and stored in the database
  234. private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {
  235. if(!txtPassword.getText().isEmpty() && !txtFirstName.getText().isEmpty() && !txtLastName.getText().isEmpty() &&
  236. !txtHouseNo.getText().isEmpty() && !txtStreet.getText().isEmpty() && !txtTown.getText().isEmpty() &&
  237. !txtPostcode.getText().isEmpty()){
  238. String password = txtPassword.getText();
  239. String firstName = txtFirstName.getText();
  240. String lastName = txtLastName.getText();
  241. String houseNo = txtHouseNo.getText();
  242. String street = txtStreet.getText();
  243. String town = txtTown.getText();
  244. String postcode = txtPostcode.getText();
  245.  
  246. String username = LoggedInCustomer.getUsername();
  247. Customer newCustomer = new Customer(username,password,firstName,lastName,houseNo,street,town,postcode);
  248. DBManager db = new DBManager();
  249. db.updateCustomer(newCustomer);
  250. lblError.setText("Customer Updated");
  251. LoggedInCustomer = newCustomer;
  252. }
  253. else{
  254. lblError.setText("Please enter details in all text boxes");
  255. }
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement