Java Reference
In-Depth Information
Lab 15.3: Using Timer and TimerTask
To become familiar with using the Timer and TimerTask class.
1. Write a class named Reminder that extends TimerTask. Add a field
of type String named message, and a constructor that initializes this
field.
2. Within the run() method, simply print out the message field using
System.out.println().
3. Write a class named TestReminder that contains main().
4. Within main(), instantiate a new Timer object.
5. Within main(), instantiate three Reminder objects, each with a differ-
ent message.
6. Using the schedule() method of the Timer class that creates a single
execution task, schedule your three Reminder objects with the
Timer. Have the first Reminder scheduled immediately, the second
reminder after 30 seconds, and the third reminder after 2 minutes.
7.
Save, compile, and run the TestReminder program.
The three reminders should be displayed at the command prompt. You
should have to wait 2 minutes before seeing the final reminder.
Lab 15.4: An Applet Game
This lab ties together many of the aspects of Java that you have learned
up until now. I won't give you much help here, except to explain the
applet that I want you to write, which is a game that tests a user's skill
and quickness with the mouse. I want you to write a game that displays
a small image moving across the screen. The player of the game scores
points by clicking on the image. Here are some of the expectations for the
game.
1.
The game should be an applet so that it can be embedded in a Web
page.
Search WWH ::




Custom Search