CISC 370 Lecture Notes for Class No. 9, March 7, 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 #6

Reading:
Horstmann & Cornell, chap. 7 thru p.
Exercises:

1. (Due next Tues, March 14) Use the material covered in lecture, the material in chap 7 of Horstmann & Cornell, the java.awt javax.swing packages, and your ingenuity to design a logo for yourself using your intials, name(s), and other features. Center the frame in the middle of the screen and your logo in the center of the frame. Make sure everything stays centered if the frame is resized.

Here is an example of a logo along with its source code that I did for a research project called Linbox. The earlier Delaware applet you did could be considered a simple logo also. But this time, write an application, not an applet. I may ask some of you to demo your code in lecture so come prepared to do that.

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.

Today's Lecture Topics

  1. Improving the HelloWorld graphics

    This program is in the files example-progs/helloWorld-app/version2/HelloWorld.java and example-progs/helloWorld-app/version2/HelloWorldPanel.java . Most of the new code is in the paintCompnent() method of the HelloWorldPanel class.

    In this newer version of the hello world example, everything is centered. The frame is centered on the display screen, the oval is centered on the paintable surface of the frame, and the message is centered in the oval. Furthermore, if the frame is resized, the oval and message will also resize.

    Some things to note about this program.

    • The diagnostic output in paintComponent() tells us when this method is called. Since paintComponent() is not called explicitly, but implicitly, this helps us get a better feel for what is happening behind the scenes.
    • It is often useful to draw debugging features on graphics output to aid in getting the graphics to look right (and then they can be removed in the finished product).

      In this case, the three horizontal lines help us to see various dimensions of the font that we are using. Fonts are fairly complicated objects. Horstmann and Cornell contains a nice discussion of fonts on pp. 281-291 that deserves a careful study.

    • The Container.list() method can be used to see the current state of a frame. This can be useful when debugging.

  2. A second example of a graphics application that introduces uses traffic lights to introduce the Canvas component and a simple use of the border layout manager. The class TrafficLight creates a traffic light object and draws it on a canvas. The TrafficFrame class demos the TrafficLight class.

Back to the CISC 370 homepage.

This page has been accessed times since 9 Mar 2000.

Corrections, suggestions and comments to Bob Caviness

Copyright 2000 B. F. Caviness