File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with .isSelected

 
kat Vicap
Greenhorn
Posts: 5
  • 0
  • 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




 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code doesn't compile for me.
 
kat Vicap
Greenhorn
Posts: 5
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20399
47
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic