943,949 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1181
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 4th, 2009
0

Radio button and JButton problem

Expand Post »
Hi
how can i execute a statement if only radio button is checked and Jbutton is click? i know how to use them Individually. i try to use like this
Java Syntax (Toggle Plain Text)
  1. public void actionPerformed(ActionEvent event)
  2. {
  3. Object src = event.getSource();
  4. if (src==radio1 && src == buttonclick)
  5. JOptionPane.showMessageDialog(null,"Raido1 is checked");
  6. }

but it did not work. pls help thx
Last edited by emint; Aug 4th, 2009 at 6:34 am.
Similar Threads
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
emint is offline Offline
60 posts
since Jun 2009
Aug 4th, 2009
0

Re: Radio button and JButton problem

Don't associate an action event with the radio button, but, rather, just with the jbutton, then have the listener simply check the value of the radio button. You will probably have to build up a map with the button->radio associations (or make your own "extneds JButton" class where you can store a reference to the radio button directly), however.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Aug 4th, 2009
0

Re: Radio button and JButton problem

thank you for ur reply, how will i do this?
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
emint is offline Offline
60 posts
since Jun 2009
Aug 4th, 2009
0

Re: Radio button and JButton problem

Java Syntax (Toggle Plain Text)
  1. actionPerformed
  2. if (source == button)
  3. // if a hashmap
  4. radio = map.get(button)
  5. // if a new object
  6. radio = button.radio
  7.  
  8. if (radio.isSelected())

I assume you know how to create a map? I assume you know how to use the "extends" keyword.
Last edited by masijade; Aug 4th, 2009 at 6:55 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Aug 4th, 2009
0

Re: Radio button and JButton problem

i dun know. but i know how to use extends keyword. thx
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
emint is offline Offline
60 posts
since Jun 2009
Aug 4th, 2009
0

Re: Radio button and JButton problem

Why the map? Why not just test the button to see if it's checked?
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Aug 4th, 2009
0

Re: Radio button and JButton problem

Ok how can i test radio button is checked or not, i tried but did not work. pls help meh
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
emint is offline Offline
60 posts
since Jun 2009
Aug 4th, 2009
0

Re: Radio button and JButton problem

if (myRadioButton.isSelected()) { ...
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Aug 4th, 2009
0

Re: Radio button and JButton problem

yep ,
Java Syntax (Toggle Plain Text)
  1.  
  2. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  3.  
  4. if(jRadioButton1.isSelected())
  5. {
  6. // do the operation
  7. }
  8. else
  9. {
  10. //do nothing
  11. }
  12.  
  13. }
Reputation Points: 16
Solved Threads: 18
Junior Poster
Software guy is offline Offline
151 posts
since May 2008
Aug 4th, 2009
0

Re: Radio button and JButton problem

thank you so much, u r realy great. it worked thank you
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
emint is offline Offline
60 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Plotting some preset graphs in JAVA
Next Thread in Java Forum Timeline: pls help 'bout my assignment for tomorrow :(





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC