I finally have my address book up and running but I want to be able to update ex
ID: 3551012 • Letter: I
Question
I finally have my address book up and running but I want to be able to update existing info. Like when I search a name and pull the info but I want to change something in that entry. It should allow me save and update. however, my program doesn't let me do that.
Here is part of the code.
If u want the whole code, I will e-mail it to u because it's too big.
public SavingData obj;
@Override
public void actionPerformed(ActionEvent event) {
String nam=nameT.getText();
obj= searchInDb(nam);
if(obj!=null)
{
saveButton.setEnabled(false);
deleteButton.setEnabled(true);
dialog.dispose();
nameT.setText("");
//saveButton.setEnabled(true);
newFrame= new JInternalFrame();
newFrame.setBounds(10, 10, 100, 100);
newFrame.setVisible(true);
//getParent().add(newFrame);
add(newFrame);
newFrame.setLayout(new SpringLayout());
Container contentPane = newFrame.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
JLabel name= new JLabel("First Name: ");
contentPane.add(name);
layout.putConstraint(SpringLayout.WEST, name,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, name,5,SpringLayout.NORTH, contentPane);
// JTextField nameT= new JTextField("",50);
contentPane.add(nameT);
nameT.setText(obj.FirstName);
layout.putConstraint(SpringLayout.WEST, nameT,5,SpringLayout.EAST, name);
layout.putConstraint(SpringLayout.NORTH, nameT,5,SpringLayout.NORTH, contentPane);
JLabel lName=new JLabel("Last Name: ");
contentPane.add(lName);
layout.putConstraint(SpringLayout.WEST, lName,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, lName,25,SpringLayout.NORTH, name);
//JTextField lNameT= new JTextField("",50);
contentPane.add(lNameT);
lNameT.setText(obj.LastName);
layout.putConstraint(SpringLayout.WEST, lNameT,5,SpringLayout.EAST, lName);
layout.putConstraint(SpringLayout.NORTH, lNameT,25,SpringLayout.NORTH, nameT);
JLabel address1=new JLabel("Address1: ");
contentPane.add(address1);
layout.putConstraint(SpringLayout.WEST, address1,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, address1,25,SpringLayout.NORTH, lName);
//JTextField address1T= new JTextField("",50);
contentPane.add(address1T);
address1T.setText(obj.Adress1);
layout.putConstraint(SpringLayout.WEST, address1T,5,SpringLayout.EAST, address1);
layout.putConstraint(SpringLayout.NORTH, address1T,25,SpringLayout.NORTH, lNameT);
JLabel address2=new JLabel("Address2: ");
contentPane.add(address2);
layout.putConstraint(SpringLayout.WEST, address2,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, address2,25,SpringLayout.NORTH, address1);
// JTextField address2T= new JTextField("",50);
contentPane.add(address2T);
address2T.setText(obj.Adress2);
layout.putConstraint(SpringLayout.WEST, address2T,5,SpringLayout.EAST, address2);
layout.putConstraint(SpringLayout.NORTH, address2T,25,SpringLayout.NORTH, address1T);
JLabel city=new JLabel("City: ");
contentPane.add(city);
layout.putConstraint(SpringLayout.WEST, city,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, city,25,SpringLayout.NORTH, address2);
//JTextField cityT= new JTextField("",50);
contentPane.add(cityT);
cityT.setText(obj.City);
layout.putConstraint(SpringLayout.WEST, cityT,5,SpringLayout.EAST, city);
layout.putConstraint(SpringLayout.NORTH, cityT,25,SpringLayout.NORTH, address2T);
JLabel state=new JLabel("State: ");
contentPane.add(state);
layout.putConstraint(SpringLayout.WEST, state,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, state,25,SpringLayout.NORTH, city);
//JTextField stateT= new JTextField("",50);
contentPane.add(stateT);
stateT.setText(obj.State);
layout.putConstraint(SpringLayout.WEST, stateT,5,SpringLayout.EAST, state);
layout.putConstraint(SpringLayout.NORTH, stateT,25,SpringLayout.NORTH, cityT);
JLabel zipcode=new JLabel("Zip Code: ");
contentPane.add(zipcode);
layout.putConstraint(SpringLayout.WEST, zipcode,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, zipcode,25,SpringLayout.NORTH, state);
// JTextField zipcodeT= new JTextField("",50);
contentPane.add(zipcodeT);
zipcodeT.setText(obj.Zipcode);
layout.putConstraint(SpringLayout.WEST, zipcodeT,5,SpringLayout.EAST, zipcode);
layout.putConstraint(SpringLayout.NORTH, zipcodeT,25,SpringLayout.NORTH, stateT);
JLabel phone=new JLabel("Phone Number:");
contentPane.add(phone);
layout.putConstraint(SpringLayout.WEST, phone,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, phone ,25,SpringLayout.NORTH, zipcode);
// JTextField phoneT= new JTextField("",50);
contentPane.add(phoneT);
phoneT.setText(obj.Phone);
layout.putConstraint(SpringLayout.WEST, phoneT,5,SpringLayout.EAST, phone);
layout.putConstraint(SpringLayout.NORTH, phoneT,25,SpringLayout.NORTH, zipcodeT);
JLabel email=new JLabel("Email:");
contentPane.add(email);
layout.putConstraint(SpringLayout.WEST, email,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, email ,25,SpringLayout.NORTH, phone);
// JTextField emailT= new JTextField("",50);
contentPane.add(emailT);
emailT.setText(obj.Email);
layout.putConstraint(SpringLayout.WEST, emailT,5,SpringLayout.EAST, email);
layout.putConstraint(SpringLayout.NORTH, emailT,25,SpringLayout.NORTH, phoneT);
Explanation / Answer
Please share the code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.