I am very new to java so my question might seem stupid :p

anyway I am in a class where we are makeing a patron loading system for a library (every one else in the class is new to java also :) ) we have our basic form built and we have a submit button. what we want the button to do is once clicked it will display all the information entered and ask if the user would like to edit and continue, if they want to edit just take them back to the form so they can edit, if put send the information to a text file in comma seperated format.

right now I am having trouble getting the submit button to do anything. the code I am using right now is just a sample from a text book that once the submit button is clicked a pop up will open saying you have clicked the submit button, but I can't get it to work. Here is part of the code:

JButton SubmitButton;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
if (shouldFill) {
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
SubmitButton = new JButton("Submit");
if (shouldWeightX) {
c.weightx = 0.5;
"omited code"
SubmitButton = new JButton("Submit");
c.ipady = 0; //reset to default
c.weighty = 1.0; //request any extra vertical space
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.insets = new Insets(10,0,0,0); //top padding
c.gridx = 7; //aligned with button 2
c.gridwidth = 2; //2 columns wide
c.gridy = 13; //third row
pane.add(SubmitButton, c);
SubmitButton.addActionListener(new ButtonListener());
private class ButtonListerner implements ActionListener
public void actionPerformed(ActionEvent e)
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Submit"))
JOptionPane.showMessageDialog(null, "You clicked the first button.");

it does not like this line: SubmitButton.addActionListener(new ButtonListener()); any suggestion would be helpful, if the entire code would help I can paste that in also...but there is alot :p

Thanks :)


This article has been dead for over six months. Start a new discussion instead.