CPE 101:
Fundamentals of Computer Science 1


Spring 2003
(Sections 02 & 03 only)
Lab # 9
Do this lab before you try solving the programming assignment.
This will not be graded, but if you seek help on the Game of Life program,
you will be required to show the working code for this first.

Task Navigation Links:
| Review of Applets | Background on the Scoreboard |
| Use the Files | What Else? |
| Reminders |

Goals for this week's lab:

Several classes, plus an .html page, will be provided to you for use in both Lab #9 and Program #6. When used together, these classes provide tools to produce a 50 by 50 grid of lights. The lights can be turned on and off individually. First, learn about the program, then experiment with it.


Review of Applets

Applets are small java programs that can be transmitted over the web and executed by browsers. Applets have no main() method but, instead, implement methods that will be invoked at appropriate times by the browser.

More information about applets can be found in sections of the textbook, as well as in the class descriptions in the appendices.

One of the standard Applet methods is paint(), which the browser calls when it wants to draw the applet on the page. The method paint(Graphics page) takes a single argument, which describes the graphics environment in which it exists, and draws itself. (To see some of the things a Graphics object is capable of, see p. 681 in the text.) Everything in the applet for this lab is done from paint(). Note the use of the word "from" in that sentence: you will write your own support methods; you will use both standard Java commands plus calls to your own methods from inside paint().

How do you run an applet?

Applets are invoked through web pages, so you must create a web page that includes the applet via the APPLET tag, to tell the browser where to find the initial class of your program. Once it has loaded that class, it will search for any others it needs until it has a complete program.

The html file for running this lab's applet is called Lights.html and looks like:

<HTML>
<applet code="ShowLights.class" width=520 height=520>
</applet>
<HTML>

To run the applet, use the program appletviewer like:

prompt% appletviewer Lights.html
This will start a new window and execute the applet in it. Alternatively, you may launch a web browser, and File/Open Lights.html from there.


Background on the Scoreboard

A number of files are provided for you to use with this lab.

The file called PLN.class is precompiled. It provides a method that ScoreBoard.java will call to demonstrate the scoreboard's capabilities for you. (Right-click and "save-link-as" when you want to download this class before you compile everything below.) This code is not available to you: your task here will be to write and appropriately insert code of your own, to generate a different display.

Four additional files are also provided: You should download and compile all of them. (You will need to have downloaded PLN.class first.) The code for these classes is provided, for you to examine as you wish, but you should be able to use these files as they are, making changes only as indicated.

In detail, these classes are:

To test your applet, you will also need the HTML driver file, Lights.html Click on that link to see it run. To download it, right click on it and pick "Save link as."

And remember: In the applet environment, the origin (0,0) is the upper left corner, X counts across, and Y increases down. (Contrast this with matrices, where the origin is in the upper left corner, but rows are counted down and columns increase across!)

For your convenience, I have a Javadoc page to give you some details regarding the classes used above. Here are the javadoc files for you to review if needed.


Use the Files

Demonstrate your knowledge and understanding by modifying the classes we have distrubuted so that when you run your applet, the lights will display your name (or at least your initials):

  1. Read and understand how the program functions, starting with ShowLights.java and reading it all the way through.
  2. Once you understand how the Scoreboard classes work, test the applet with the test driver code distributed in PLN.class:
    	DOS> javac *.java
    	DOS> appletviewer Lights.html
    	
    You should see a new window appear with a display that has already been set up.
  3. Once you've done the demo, go through the code again, tracing its operation in detail to be sure you understand how it's all working.
  4. Now (and only now), modify the method drawDesign() in ScoreBoard.java to draw your own design on the screen. Put your name in lights, or some other suitable demonstration of your ability to control the board. What exactly you do here isn't terribly important, since the real demonstration of your ability will come in the Game of Life. But be sure that what you do here isn't trivial, so you really understand whatis going on. For example, you might first display a word or design on the screen, and then modify the program to make it move around the board a number of times, ending in some interesting position.

What Else?

You should document your understanding of this lab. There are several ways to do this: by thoroughly commenting the code provided (we were sparse with comments, on purpose, so you'd have to figure out what was happening rather than just rely on our notes); by your own separate design document; or by various combinations of those. Do not skip this step. It will come in handy as you work on the programming assignment, review for the final, and/or come across the need for similar processes in later courses.


Requirements & Reminders
Site Navigation Links:
Onward: To the associated programming task
Back: This Instructor's CSC-101 HomePage
Up: This Instructor's HomePage

Copyright © 2000-01 by Carol Scheftic & Phil Nico, and Clark S. Turner, 2003. All rights reserved.
Requests to reuse information from this page should be directed to Carol Scheftic.
Page created 1 April 2001; last updated May 2003