• 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

checkboxes

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all;
Here is my dilemma. I am working on a GUI for a fictious pizza restaurant. I have check boxes for the toppings. Everytime a user selects a specific topping; the total number of toppings should increase by 1. If the user deselects a specific topping, it should decrease the total number of toppings by 1. I want the program to keep a running total of the number of toppings selected.
I'm not sure how to get started on this. I am using the ItemListener to listen for the checkboxes. Any help would be greatly appreciated.
For example: if the available toppings are pepperoni, sausage, and onions, and the user selects pepperoni and onions, the total number of toppings selected should display 2. Also each topping can only be added to the pizza one time.
I am just looking for a push in the right direction.
Thanks
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the ItemEvent class in the Java API. There is a method you can use to determine when a topping is checked or unchecked.
Matthew Phillips
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use itemlistener and make an addItemlistener call to each checkbox. Try using an inner class for ItemListener. Good practice. Something like.
<CODE>
Checkbox cb = new Checkbox( "test" );
cb.addItemListener( new ItemListener() {
public void itemStateChanged( ItemEvent e ){ System.out.println( "an event occured" );
}
} );
</CODE>
A static int would be nice to increment and decrement to hold count on how many checkboxes that are checked.
Hope this helps!
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic