• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem while selecting radio buttons

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Abhimanyus singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> .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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.

reply
    Bookmark Topic Watch Topic
  • New Topic