CS 110 Introduction to Computing
Project #2: Moving Target!
In this project you will be writing your first "event driven" applet. The goal of this applet is to draw a figure that looks like a target at which you might shoot an arrow (i.e., several concentric circles). As with a real target, your target should get larger and smaller (to simulate walking towards and away). Similarly, you target should change from a circle to and oval to invisible -- or perhaps just a thin line -- to simulate walking arround the target.
To implement the simulated changes in distance and viewing angle use two scrollbars. For example, here are some snapshots of my black and white version of this applet. The upper scrollbar controls the simulated distance, the lower controls the simulated viewing angle. The angle scrollbar ranges from 0 to 90 where 0 is straight ahead and 90 is looking at the side of the target.
| |
|
Close to the target and nearly directly ahead of it. | Still close, but off to the side. | Farther away and still off to the side
|
Due Date: September 28, at the beginning of class.
Submit:
- A printout of the code for your applet.
- Several printouts of your applet showing change in size and viewing angle.
- The URL of the HTML page containing your applet
Notes
To get a printout of an applet in the lab do the following (changing XXXX as appropriate to your file names):
- in a terminal window enter: appletviewer XXXX.html &
- in a terminal window enter: import XXXX.jpg
- click once in the appletviewer window (the cursor should look kind of like a +)
- in a terminal window enter: lpr XXXX.jpg
The following code snippet might be very helpful in dealing with changes in viewing angle:
|
int viewingAngle = 45; // measured in degrees
int radius = 60;
int xRadius = (int)(Math.cos((viewingAngle*Math.PI)/(2*90))*radius);
|
To make you scrollbars go all the way across the top of the applet put the following line at the top of your init method:
|
setLayout(new GridLayout(10,1));
|
Extra Credit
5 points: Add a third scroller to simulate vertical rotation.
5 points: Keep your target centered in the applet as the size of the applet, size of the target, and viewing angle all change. Also, make sure that your target never goes off the applet.