This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes help with .isSelected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "help with .isSelected" Watch "help with .isSelected" New topic
Author

help with .isSelected

kat Vicap
Greenhorn

Joined: Oct 17, 2009
Posts: 5
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




pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Your code doesn't compile for me.
kat Vicap
Greenhorn

Joined: Oct 17, 2009
Posts: 5








but still i got a NULL POINTER EXCEPTION after i compiled.. guys please help
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Oct 17, 2009
Posts: 5
i got the thing to compile now. but the charge is so messed up.

GUI



EVENTS
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

"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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with .isSelected
 
Similar Threads
Adding Record Problem in JDBC ?
SWING GUI ADVICE,PLEASE
SWING GUI ADVICE,PLEASE
Getting a problem while using database connectivity
Switching between the frames