• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

urgent!!!!!!!

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys! how can i capture the state of the radio button, I mean whether it is clicked or not. I am constructing it with the constructor. the code is as follows.......
JRadioButton selection = JRadioButton("example",false);
selection.addMouseListener(new GridListener());
public class GridListener extends MouseAdapter{
public void mousePressed(MouseEvent e){
_____________________



}
}
Thanks in advance..........
 
Author
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ask the source of the event.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
 
Surya Renduchintala
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey john!
I want to do some things if it selected(true) and if it is made false I want to do some other things. I can get the source by e.getSource() but how can I know whether it is made true or not?. pls help me
thanks in advance.....
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's a radio button the event is fired when the button is clicked then the getSource() method will tell you which button was clicked.
the other option is to use the getStateChange() which will tell you if it was selected or deselected.
hope that helps
Dave
 
Surya Renduchintala
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guys!
i have only one radio button and as u suggested dave , i dont find any getStateChange in JRadioButton class. can some pls help!!!
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the getStateChange() method is in the ItemEvent class. however if you only have one radio button can't you just use a JCheckBox? then register a listener on it like this:
buttonName.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
if ( e.getStateChange() == ItemEvent.SELECTED )
//do something
}
});
now when the button is checked or unchecked it'll fire a ItemEvent and you can use the getStateChange() event to see if it was selected or unselected.
Dave
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops, my last sentence should say the getStateChange() method not event. Don't want to confuse anyone, sorry 'bout that.


Dave
 
A feeble attempt to tell you about our stuff that makes us money
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic