• Post Reply Bookmark Topic Watch Topic
  • New Topic

Action Listeners

 
Daniel Hoyt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a GUI to enter a persons name, their pledge amount, and then there are radio buttons to select a charity they want the pledge to go to. I have most of this done, however here is my problem.
When the SUBMIT button is pressed it should enter information into the JTextArea box so that the info can be reviewed and then confirmed. I made an action listener to determine if and which radio button is pressed. How do I pass this information into the submitButton action listener so that it will populate the JTextArea with the rest of the information when the Submit button is pressed. I hope I made my question clear as I almost confused myself writing this...
Here is the code...

 
Jorge Montes
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,

Your problem is in the RadioButtonListener class, this is a inner class with a local charityText variable, so, when you are attempting to change it you are only changing the local variable.

Just replace it with this:

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'Object Oriented Way' starts with an Object that represents the data. You might call it CharitableContribution. And it would have fields for the donor's name, amount, and name of the charity. When the form is first shown, a new instance is created with appropriate default values (the same defaults as shown in the GUI when it is first displayed). Then, each time a field in the form is changed, it propagates the change to the instance of the CharitableContribution. For example, the ActionListener for the radio buttons would do:

Similarly for the names and pledge (which also have action listeners by the way).

Then in the Submit action, you would take the values out of the data holding Object, and do what you want: create a displayable text for the pledgeInfo text area. You can also use the same Object to transport the data to whatever happens next (whatever code is responsible for storing or processing the values).
 
Daniel Hoyt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jorge Montes wrote:Hi Daniel,

Your problem is in the RadioButtonListener class, this is a inner class with a local charityText variable, so, when you are attempting to change it you are only changing the local variable.

Just replace it with this:


Thank you so much for your help, still trying to learn and was getting extremely frustrated. I have another question about my code, am I allowed to do it here or should I post a new question in a new thread?? Thanks again for your time.

 
Jorge Montes
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is about the above code i don't see a reason why you can't
 
Daniel Hoyt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jorge Montes wrote:If it is about the above code i don't see a reason why you can't


It is.
My question is, my size is way off. I tried to do pack() but when I run it, its all gone, minimized. When I do a setSize, no matter the size, it doesn't seem to fully display.
 
Jorge Montes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To achieve this you should use a LayoutManager, like BorderLayout (implements LayoutManager), these are containers created to JComponents (like Jpanel) do not get overlapped.

Here is BorderLayout API http://docs.oracle.com/javase/6/docs/api/java/awt/BorderLayout.html

Good Luck!
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jorge Montes wrote:To achieve this you should use a LayoutManager, like BorderLayout (implements LayoutManager), these are containers created to JComponents (like Jpanel) do not get overlapped.

Many layout managers prevent overlapping, but BorderLayout doesn't. See JScrollPane overlapping with JTabbedPane.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!