• Post Reply Bookmark Topic Watch Topic
  • New Topic

Applet won't calculate  RSS feed

 
Ryan Daguman
Ranch Hand
Posts: 33
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet program here that allows the user to choose a movie then a number of tickets from a drop-down list. A check box should display for users to click so they can receive a discount for matinee movies. The user should be able to click a calculate price button to display the total cost and a clear button to clear each drop-down list and the check box. The program compiled but when I clicked the calculate button, it generated so many error codes like java.lang.nullPointerException and a lot more. I just wanted the program to work properly so please help me. Please refer to the code below:



The applet code:


Pardon me for the clumsy design because I didn't create a layout manager. I very much welcome tips and comments to further improve the code for this program. Thank you so much!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, string equality is checked using the "equals" method, not with the "==" operator.

Secondly, you can't access "presyoKo[i]" until that array has been created. So far, the code declares it, but doesn't create the actual array - for example, "double presyoKo[] = new double[15]" would allow you to store 15 values in it.

And yes - you should use proper layouts.
 
Ryan Daguman
Ranch Hand
Posts: 33
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the actionPerformed method and itemStateChanged blocks of my program. There are two buttons and choice components in my program that's why I have both the actionPerformed and itemStateChanged methods. The program works fine but what method should I use with the matineeBox checkbox to disable it (not clickable) and it will only be active or can be checked once the user clicks the calculate button and the charge displays?


And could you please advise me how to get the value of the choice component (ticketsChoice) without creating a user-defined class. The user-defined class here is: catcher[i] = new Proj4exe2Class(ticketPrice);
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use Code Tags.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That method is far too large and should be converted to several methods.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!