Re: Applet help for beginner
Tomek wrote On 05/23/06 12:05,:
Hi!
Can anyone help with my exercise?
I have to prepare an applet which include a counter. Thanks to Up and Down
buttons I can increase or decrease its value. Thanks to the Detonate button
the counter starts to decrease to zero and then the writing Explosion
should appear.
I can prapare background and buttons but nothing more:(
You can use a JLabel to display the current value
of the counter, and to display "Explosion" when the
right time comes. Use the setText() method to change
what the JLabel displays.
The Up button should have an ActionListener that
increments a counter and displays the new count in the
JLabel. The Down button should have an ActionListener
to go the other way (and probably to "stick" at zero).
The Detonate button should have an ActionListener
that disables all the buttons (use their setEnabled()
methods). Then as long as the counter is positive it
should decrement the count, display the new value, and
pause for a suitable interval. (Thread.sleep() is good
enough for a simple program like this; a fancier program
might use a Timer object.) When the counter reaches
zero, change the JLabel to display "Explosion" and then
re-enable the buttons so the user can indulge his
destructive fantasies again.
--
Eric.Sosman@sun.com