• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a 'Save' button  RSS feed

 
Maria Tobin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya All,

I'm a Java beginner and am learning -slowly - as I go along. I've created a simple Banking app. It was working successfully using RMI. But now I'd trying to learn swingand apply it to this programme.

I've created a CreateCustomer method and using 'ListModel' have created some customers so far so good. But then I have a number of text fields on a jframe and the user can put information into these boxes. Next they should click on a 'Save' button and then entered information is saved.

I've tried the following but it's not working at all and I would really like some advice. The more I work on it the more confused I seem to get. Any advice would be great. Thanks

JButton btnSave = new JButton("Save");
btnSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
MakeCustomers mc = MakeCustomers.getInstance();
Customer c = mc.newCustomer();
c.setName(txtName.getText());
c.setAccountNumber(txtNumber.getText());
c.setType(txtType.getText());
c.setBalance(txtBalance.getText());
c.setApr(txtApr.getText());
((CustomerListModel)customerModel).addCustomer(c);
}
});
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then your next step should be to describe in what way it doesn't work. For example, does your code not compile? Or does it throw exceptions when you run it? Or does it do something different than what you expected it to do? Quoting error messages, if any, would be helpful too. And explaining what you expected it to do would be helpful -- the code you posted doesn't appear to do anything which I would describe as "saving" but maybe that's just a terminology problem.

And in future when you post code it makes the code easier to read if you click the "Code" button above the posting box and then paste your code between the tags which appear.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

That question would sit better on the Swing forum. Moving thread.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!