Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Allows for customers to edit their own details
- public class EditCustomer extends javax.swing.JFrame {
- Customer LoggedInCustomer;
- public EditCustomer(Customer customer) {
- LoggedInCustomer = customer;
- initComponents();
- txtUsername.setText(LoggedInCustomer.getUsername());
- txtPassword.setText(LoggedInCustomer.getPassword());
- txtFirstName.setText(LoggedInCustomer.getFirstName());
- txtLastName.setText(LoggedInCustomer.getLastName());
- txtHouseNo.setText(LoggedInCustomer.getAddressLine1());
- txtStreet.setText(LoggedInCustomer.getAddressLine2());
- txtTown.setText(LoggedInCustomer.getTown());
- txtPostcode.setText(LoggedInCustomer.getPostcode());
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- btnBack = new javax.swing.JButton();
- jLabel2 = new javax.swing.JLabel();
- txtUsername = new javax.swing.JTextField();
- jLabel3 = new javax.swing.JLabel();
- txtPassword = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- txtFirstName = new javax.swing.JTextField();
- jLabel5 = new javax.swing.JLabel();
- txtLastName = new javax.swing.JTextField();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- txtHouseNo = new javax.swing.JTextField();
- jLabel8 = new javax.swing.JLabel();
- txtStreet = new javax.swing.JTextField();
- jLabel9 = new javax.swing.JLabel();
- txtTown = new javax.swing.JTextField();
- jLabel10 = new javax.swing.JLabel();
- txtPostcode = new javax.swing.JTextField();
- btnSubmit = new javax.swing.JButton();
- btnUndo = new javax.swing.JButton();
- lblError = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("EDIT MY DETAILS");
- btnBack.setText("BACK");
- btnBack.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnBackActionPerformed(evt);
- }
- });
- jLabel2.setText("Username:");
- jLabel3.setText("Password:");
- jLabel4.setText("First Name:");
- jLabel5.setText("Last Name:");
- jLabel6.setText("Address -");
- jLabel7.setText("House/Flat Number:");
- jLabel8.setText("Street:");
- jLabel9.setText("Town:");
- jLabel10.setText("Postcode:");
- btnSubmit.setText("SUBMIT");
- btnSubmit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnSubmitActionPerformed(evt);
- }
- });
- btnUndo.setText("UNDO CHANGES");
- btnUndo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnUndoActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(btnBack)
- .addGap(65, 65, 65)
- .addComponent(jLabel1))
- .addGroup(layout.createSequentialGroup()
- .addGap(73, 73, 73)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txtLastName))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))))
- .addGroup(layout.createSequentialGroup()
- .addGap(169, 169, 169)
- .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel8)
- .addComponent(jLabel7)
- .addComponent(jLabel9)
- .addComponent(jLabel10))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtHouseNo)
- .addComponent(txtStreet)
- .addComponent(txtTown)
- .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(btnUndo)
- .addGap(131, 131, 131))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(btnSubmit)
- .addGap(153, 153, 153))))
- .addGroup(layout.createSequentialGroup()
- .addGap(65, 65, 65)
- .addComponent(lblError, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 67, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(17, 17, 17)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(btnBack))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel6)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel7)
- .addComponent(txtHouseNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel8)
- .addComponent(txtStreet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel9)
- .addComponent(txtTown, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel10)
- .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(lblError, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnSubmit)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnUndo)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- //When the back button is pressed, the user is taken back to the CustomerHome page
- private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
- CustomerHome customerHome = new CustomerHome(LoggedInCustomer);
- this.dispose();
- customerHome.setVisible(true);
- }
- //When the Undo button is pressed, the user's data that's stored in the database appears in the textboxes
- private void btnUndoActionPerformed(java.awt.event.ActionEvent evt) {
- txtUsername.setText(LoggedInCustomer.getUsername());
- txtPassword.setText(LoggedInCustomer.getPassword());
- txtFirstName.setText(LoggedInCustomer.getFirstName());
- txtLastName.setText(LoggedInCustomer.getLastName());
- txtHouseNo.setText(LoggedInCustomer.getAddressLine1());
- txtStreet.setText(LoggedInCustomer.getAddressLine2());
- txtTown.setText(LoggedInCustomer.getTown());
- txtPostcode.setText(LoggedInCustomer.getPostcode());
- lblError.setText("");
- }
- //When the Submit button is pressed, the user's data is updated and stored in the database
- private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {
- if(!txtPassword.getText().isEmpty() && !txtFirstName.getText().isEmpty() && !txtLastName.getText().isEmpty() &&
- !txtHouseNo.getText().isEmpty() && !txtStreet.getText().isEmpty() && !txtTown.getText().isEmpty() &&
- !txtPostcode.getText().isEmpty()){
- String password = txtPassword.getText();
- String firstName = txtFirstName.getText();
- String lastName = txtLastName.getText();
- String houseNo = txtHouseNo.getText();
- String street = txtStreet.getText();
- String town = txtTown.getText();
- String postcode = txtPostcode.getText();
- String username = LoggedInCustomer.getUsername();
- Customer newCustomer = new Customer(username,password,firstName,lastName,houseNo,street,town,postcode);
- DBManager db = new DBManager();
- db.updateCustomer(newCustomer);
- lblError.setText("Customer Updated");
- LoggedInCustomer = newCustomer;
- }
- else{
- lblError.setText("Please enter details in all text boxes");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement