CISC 370 Lecture Notes for Class No. 10, March 9, 2000

Course Home Prev Lect Next Lect Example Progs Exercise Solns
CoreJava Progs
Documentation
Gen'l Docs Java 2 APIs Java Glossary Term Proj Info

Graded Assignment #7 Due Tues 3/21. Note that term project proposals are also due on Tues 3/21

Reading:
Horstmann & Cornell, remainder of chap. 7
Exercises:

1. Create a class PedLight analogous to TrafficLight that extends JPanel. It should have two states: (a) one with a green background and the word "Walk" in large letters centered on the background, and (b) a second with a red back ground with the phrase "Don't Walk" in the same large font centered on it. Then create a PedFrame class, analogous to TrafficFrame, that puts two instances of PedLight, one in each state, on a frame with one at the top, NORTH, and the other at the bottom, SOUTH. Do not forget to include the methods getMinimumSize() and getPreferredSize() in PedLight.

To prepare programming assignments for submission, do the following for each exercise.

script	        // Produces a file named typescript
whoami 
date 
pwd 
cat *.java 
javac *.java     // mainFile should be the name of the file containing
java mainFile    // your main() method
exit		 // to exit script

Now print the typescript file for submittal at the beginning of lecture.

On strauss, you can use xv as demoed in lecture to grab and print a copy of the graphics output from your Java programs that should be handed-in with your assignment.

Today's Lecture Topics

  1. Using xv to grab and print graphics windows produced by Java programs. xv can also be used to save such images in .gif or .jpeg formats that can then be use anyway such files are normally used including referencing and displaying them from html files. That is the way the above helloworld images were produced.

  2. Version 2 of the Class TrafficLight .

    Particularly notice the following features of this code.

    1. The use of the method TrafficLight.setOnLight in the one-param constructor to eliminate code duplication to verify that the color to which to initialize the light is correct.
    2. The use of the PrintStream err in the warning mesage in TrafficLight.setOnLight(). System.err corresponds to cerr of C++.
    3. The use of the methods Color.brighter() and Color.darker() to turn the traffic lights on or off.

Back to the CISC 370 homepage.

This page has been accessed times since 10 Mar 2000.

Corrections, suggestions and comments to Bob Caviness

Copyright 2000 B. F. Caviness