CSC 241- Assignment 1 (Due February 10th 1997)
You will develop your first applet here. Develop a traffic
light that you can control with a switch button. To see what your light
should look like follow the link for Traffic Light . Be aware that your traffic light will behave slightly differently than mine does.
- Use the Save As... option in the File pull-down menu of
Netscape to save the html file that I have written for my traffic light.
- Change the codebase to reflect where your classes
directory is:
codebase="http://www.oswego.edu/~your account/classes/"
- For code, provide the address of the .class file
relative to the classes directory. For example, if you name the file
for your traffic light class, tr.java and place it in your
csc241 subdirectory, you will need the following
code statement:
code="csc241.tr.class". Also, in this example, you must
have csc241 as your package name in the tr.java file
itself.
- Develop a Java applet that displays a traffic light with similar
dimensions as mine with an obvious difference in the way the light
changes as described below.
- Your rectangle should be filled with black. The three circles, red,
yellow, and green, should be designed to be drawn inside the
rectangle in a reasonably symmetrical manner.
- Circles representing each light should be gray when off, and should
have the appropriate color when on.
- There must be a switch button.
- The light must start as red.
- Each time the Switch button is clicked, it should change to
the next color. When traffic light is red and the button is
clicked, the light should change to green. When the light is
green and the button is clicked, the light should change to
yellow. When the light is yellow and the button is clicked,
the light should change to red.
Building the traffic light that works like mine (When green and
switch is clicked, change light to yellow, pause, then to red),
requires a more in-depth knowledge of how applets work than you
have at this point, so don't try to do that.
- To find the right Graphics methods, follow the link to
Graphics class.
Also, check out hello3.java for hints on drawing things
and creating buttons and what methods you need to write.
- Email me the URL for the traffic light's HTML file, also include a link to it in your homepage.
- Email your .java file as an attachment.
- Remember that your .class file and the .html file and
the path to them must be public, but DO NOT make your
.java file public. Check out
Lab #1
on how you make files public.