aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem while selecting radio buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem while selecting radio buttons" Watch "problem while selecting radio buttons" New topic
Author

problem while selecting radio buttons

Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
Hi guys..
I'm trying to develop a small program using swing which is supposed to work as follows..
upon selecting first radio the dialog box should show RED...upon selecting the second radio button, the dialog box should show YELLOW...and WHITE for the third radio button...

But,I'm confused because for the first click on any of the 3 radiobuttons the app. works fine and shows only one dialog box, but as soon as the second Radio button is clicked ,lets say, the one named RED after clicking WHITE.... 2 dialog boxex appear, one hidden behind another...one showing WHITE...otherone showing RED...but it should display only one dialog box....

the code is:

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Hello Abhimanyus and welcome to the Ranch! For posting code here, please UseCodeTags <- link which I've added for you this time.

Also, for getting better help on this or any other Java forum, it would be good for you to learn and respect the Java Coding Conventions, as that makes your code so much more readable for other coders. Variable names should start with a lowercase letter.

Read the API for ItemEvent. You'll find a method to determine whether the event corresponds to a selection or a deselection. Does that give you a clue why your program behaves the way it does?


luck, db
There are no new questions, but there may be new answers.
Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
Darryl Burke wrote:Hello Abhimanyus and welcome to the Ranch! For posting code here, please UseCodeTags <- link which I've added for you this time.

Also, for getting better help on this or any other Java forum, it would be good for you to learn and respect the Java Coding Conventions, as that makes your code so much more readable for other coders. Variable names should start with a lowercase letter.

Read the API for ItemEvent. You'll find a method to determine whether the event corresponds to a selection or a deselection. Does that give you a clue why your program behaves the way it does?



Hi...is getStateChange() the method, you are talking about, but that returns an integer value ...but then, which integer value will correspond to the each one of the radio buttons?? Please help...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> .is getStateChange() the method

read it again - the returned int is not a random int - so you have the option of checking 'what' has been returned.
Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
Michael Dunn wrote:> .is getStateChange() the method

read it again - the returned int is not a random int - so you have the option of checking 'what' has been returned.


Hi...as i'm new to this GUI programming..it would be great help to me...if you elaborate the usage of ItemListener's methods with regard to my example !!!


regards.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> as i'm new to this GUI programming

the solution has nothing to do with GUI programming,
its all about the must-have ability to read/interpret/understand
the docs.

here's a simple program, run it, 'Red' will be selected, click 'White'
and study the output - the solution to your problem will be staring you
in the face.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem while selecting radio buttons