Radio button and JButton problem

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

Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Radio button and JButton problem

 
0
  #1
Aug 4th, 2009
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
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 266
Moderator
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven

Re: Radio button and JButton problem

 
0
  #2
Aug 4th, 2009
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Re: Radio button and JButton problem

 
0
  #3
Aug 4th, 2009
thank you for ur reply, how will i do this?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 266
Moderator
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven

Re: Radio button and JButton problem

 
0
  #4
Aug 4th, 2009
  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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Re: Radio button and JButton problem

 
0
  #5
Aug 4th, 2009
i dun know. but i know how to use extends keyword. thx
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,004
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 149
JamesCherrill JamesCherrill is online now Online
Veteran Poster

Re: Radio button and JButton problem

 
0
  #6
Aug 4th, 2009
Why the map? Why not just test the button to see if it's checked?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Re: Radio button and JButton problem

 
0
  #7
Aug 4th, 2009
Ok how can i test radio button is checked or not, i tried but did not work. pls help meh
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,004
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 149
JamesCherrill JamesCherrill is online now Online
Veteran Poster

Re: Radio button and JButton problem

 
0
  #8
Aug 4th, 2009
if (myRadioButton.isSelected()) { ...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 38
Reputation: Software guy is an unknown quantity at this point 
Solved Threads: 2
Software guy Software guy is offline Offline
Light Poster

Re: Radio button and JButton problem

 
0
  #9
Aug 4th, 2009
yep ,
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Re: Radio button and JButton problem

 
0
  #10
Aug 4th, 2009
thank you so much, u r realy great. it worked thank you
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC