This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

help with .isSelected

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Your code doesn't compile for me.
 
kat Vicap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
i got the thing to compile now. but the charge is so messed up.

GUI



EVENTS
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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.
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic