• 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

help with .isSelected

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a problem with the Jcheckbox listener. i set the initial charge to 10. and for every checkbox selected, the charge should increment to 1. however, decrements to 1 as well when desselected. the problem with my code is that the incrementation and decrementation only works for ONE checkbox. when i the second box is selected, it wont increment the charge neither decrements when unselected. please help




 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code doesn't compile for me.
 
kat Vicap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator








but still i got a NULL POINTER EXCEPTION after i compiled.. guys please help
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

love fox wrote:
but still i got a NULL POINTER EXCEPTION after i compiled.. guys please help



The NPE will tell you exactly which line is causing it. On that line you are trying to use an object that has not been initialized. For instance, I see that you've declared a JCheckBox array but I don't see that you've ever initialized it. Perhaps this is causing your problem.

Other suggestions:
1) Use descriptive variable names throughout. For example, instead of p2, use chkBoxPanel, instead of e, use checkBoxListener, etc...

2) use an array of String for your checkbox labels. This way you can consolidate your code quite a bit. i.e.,


3) Put in clinic a public method to count the number of checkboxes clicked (easy if you have traverse the array). Have the Listener call this method.

4) Put in clinic a public method to change the charge label
 
kat Vicap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got the thing to compile now. but the charge is so messed up.

GUI



EVENTS
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"love fox", you've been warned about your name before, two days ago. Apparently you have not noticed that warning; consider this a second chance to fix it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic