saving data from multiple JTextFields...

I am creating a program for myself to manage my bills/account information. When I click on a button "create new account" another window will pop up, with a text box for account name, address, and any other important information. I am just wondering if I need to have an action listener for each text field, or if it is possible to have my save button use an action listener that will somehow store the date from each JTextField into the proper area.

Below is an example of the text fields. I am thinking that I might have to have a different name for each text field, rather than reusing the same textField and textFieldLabel. Any input is appreciated.

-dub stylee

JPanel accountInfoPanel =new JPanel(new GridBagLayout());

accountInfoPanel.setBorder(

BorderFactory.createCompoundBorder(

BorderFactory.createTitledBorder("Add New Account"),

BorderFactory.createEmptyBorder(5, 5, 5, 5)));

textField =new JTextField(25);

textFieldLabel =new JLabel("Creditor Name:");

textFieldLabel.setLabelFor(textField);

c.gridx = 0;

c.gridy = 0;

accountInfoPanel.add(textFieldLabel, c);

c.gridx = 1;

accountInfoPanel.add(textField, c);

textField =new JTextField(25);

textFieldLabel =new JLabel("Address Line 1:");

textFieldLabel.setLabelFor(textField);

c.gridx = 0;

c.gridy = 1;

accountInfoPanel.add(textFieldLabel, c);

c.gridx = 1;

accountInfoPanel.add(textField, c);

[1774 byte] By [dub_styleea] at [2007-11-27 3:02:45]
# 1

You do not need a ActionListener on every JTextField except you want to validate directly after a Return. One ActionListener at the end attached on the OK-button for submitting is enough. The ActionListener can access the values of the text fields if the variables are final or object variables.

Sincerely

Christian Ullenboom | http://www.tutego.com/

Christian.Ullenbooma at 2007-7-12 3:45:50 > top of Java-index,Desktop,Core GUI APIs...
# 2
If your planning on building big forms with a lot of fields try JGoodies binding.this can bind the fields directly to the object you want to write...
S1lv3ra at 2007-7-12 3:45:50 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks for the help, I was able to get it to work by just adding the action listener to the button at the end of the form. It took some messing around to figure out how to get the button to access the text fields, but it works now. :)dub
dub_styleea at 2007-7-12 3:45:50 > top of Java-index,Desktop,Core GUI APIs...