Swing Button question

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 30
Reputation: Stewie is an unknown quantity at this point 
Solved Threads: 0
Stewie Stewie is offline Offline
Light Poster

Swing Button question

 
0
  #1
Apr 26th, 2006
Hello,

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:

  1. JButton SubmitButton;
  2. pane.setLayout(new GridBagLayout());
  3. GridBagConstraints c = new GridBagConstraints();
  4. if (shouldFill) {
  5. //natural height, maximum width
  6. c.fill = GridBagConstraints.HORIZONTAL;
  7. }
  8.  
  9. SubmitButton = new JButton("Submit");
  10. if (shouldWeightX) {
  11. c.weightx = 0.5;
  12. }
  13. "omited code"
  14. ...
  15. ...
  16. ...
  17. SubmitButton = new JButton("Submit");
  18. c.ipady = 0; //reset to default
  19. c.weighty = 1.0; //request any extra vertical space
  20. c.anchor = GridBagConstraints.PAGE_END; //bottom of space
  21. c.insets = new Insets(10,0,0,0); //top padding
  22. c.gridx = 7; //aligned with button 2
  23. c.gridwidth = 2; //2 columns wide
  24. c.gridy = 13; //third row
  25. pane.add(SubmitButton, c);
  26.  
  27. SubmitButton.addActionListener(new ButtonListener());
  28.  
  29. }
  30.  
  31. private class ButtonListerner implements ActionListener
  32. {
  33. public void actionPerformed(ActionEvent e)
  34. {
  35. String actionCommand = e.getActionCommand();
  36.  
  37. if (actionCommand.equals("Submit"))
  38. {
  39. JOptionPane.showMessageDialog(null, "You clicked the first button.");
  40. }
  41. }
--------------------------------------------------------------------
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

Stewie
Last edited by cscgal; Apr 26th, 2006 at 10:22 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Swing Button question

 
0
  #2
Apr 26th, 2006
Here's two links about file handling and making GUI's it's all you need.
Read them.

http://java.sun.com/docs/books/tutor.../io/index.html


http://java.sun.com/docs/books/tutor...tml#components
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC