Java Reference
In-Depth Information
2. Use JApplet for your applet and Swing components for any GUI
components you use.
3. To create the image that moves across the screen, you can create a
bitmap image using a program such as Microsoft Paint. Alternately,
an easier way is to use one of the drawing methods of the
java.awt.Graphics class. Check the documentation for the Graphics
class and browse through the methods. For example, the fillOval()
method can be used to draw a circle, or the fillRect() method draws
a rectangle. (Hint: A rectangle can simplify your math considerably
when you try to determine whether the user clicked on the image
or not.)
4. Write a thread that contains a reference to the content pane of the
JApplet. The thread should draw the image on the screen, sleep for
a specified amount of time, and then redraw the image somewhere
else on the screen. You can also display the image in different sizes
to make the game more challenging.
5. Provide a JTextField that displays the sleep time of the thread. The
users should be able to change this value, depending on how fast
they think they are. Add the corresponding event handling that
changes the sleep time in the thread class.
6. Add a JLabel that displays the score. You can score the game how-
ever you like. A simple scoring might be 10 points for hitting the
object, or perhaps you can offer more points for hitting the object
quickly or for hitting the object when it is smaller.
7. You will need a MouseListener to handle the mouseClicked() event.
This class will need to determine whether the object was hit, and if
so, how many points to award.
8. Write an HTML page that embeds your JApplet. This program will
probably require lots of testing, so the appletviewer might come in
handy.
You should be able to embed your applet in a Web page and play the
game.
Search WWH ::




Custom Search