CSCI A348
Mastering the World-Wide Web

Spring `96 Assignment #4
Java Lab #1: 4-5 April 1996

Attendance and participation in this lab, along with the other Java labs, form the grade for this assignment. Students not able to attend a lab may demonstrate mastery of the lab exercises to the lab AI outside of class for the grade credit. Students with more Java/programming experience should pair with less experienced students to work together at a workstation in the labs. The less experienced student should drive the console with the more experienced student tutoring and advising to complete as much of the following exercises as they can during the lab period. Collaboration and questions are encouraged.

Goal 1: Compile and run a Java application
Do the "Hello World" application exercise in the Java tutorial. Note that javac, java, and all Java commands on the Burrow, are located in /l/java/bin. I recommend either placing this directory in your Unix default PATH environment variable, or creating an alias in your .cshrc file to do so when needed, eg:
alias +java  'set path = ( $path /l/java/bin )'
Goal 2: Compile and run a Java applet
Do the "Hello World" applet exercise in the Java tutorial. Run the applet with the JDK appletviewer, Netscape (netscape) and HotJava (hotjava). Do they all work? Do you detect any differences?
Goal 3: Investigate usage of standard applet methods
Write a skeletal applet of your own containing only the init, update, paint, start, stop and destroy methods. Refer to the API User's Guide for their proper usage. Each method should contain only a single print statement to indicate the method was invoked, eg:
public void init() {
	System.out.println("Running init ...");
}
Compile your applet and run it with appletviewer and Netscape.
  1. Where does the output go with each of these viewers?
  2. Do they both interact with standard applet methods in the same way?
  3. What is the sequence of methods invoked by the viewers?
  4. What happens when you leave the page, iconify the viewer, or cover and uncover the applet?
  5. What has to happen for paint to be invoked?
  6. How many times can you make start get invoked? stop?
  7. Where does the output go if you use showStatus() instead of System.out.println()?
Goal 4: Investigate usage of applet event methods
Expand your applet from the previous goal to include the mouseEnter, mouseExit, mouseDown, mouseUp, mouseDrag, mouseMove, gotFocus, lostFocus, keyDown and keyUp methods with simple print statements as before. Refer to the API User's Guide for their proper usage. Make sure the non-void methods return an appropriate value. Compile your applet and run it with appletviewer and Netscape.
  1. Can you have a mouseDown event that is not followed by a mouseUp event?
  2. Can you have a mouseDown event that is not followed by a mouseDrag event?
  3. Can you have a mouseUp event that is not preceded by a mouseDown event?
  4. What's the most common event? Why?
  5. Are there any events you don't see?
  6. Of those events you can make occur, exactly how do you do it? How many different ways can you do it?
Goal 5: Print method arguments
Modify your applet from the previous goal so the applet methods print their arguments as well as the notification string. Note that Java will try to use a string representation of an object when the object is concatenated with a string using the plus operator. This is an implicit conversion of an object to a string. How could one be explicit about it? What do Event and Graphics objects print as?
<kinzler@cs.indiana.edu> 3 April 1996