CS150 Lab 10: Threading an Applet

Due Sunday, 12/3/00 at 11:59 PM

This week we will get our first taste of an Applet in Java.   We will also explore the use of multiple threads in a program and how to control the behavior of one thread from another.  

To accomplish these pedagogical goals, we will build an animation that is very similar in concept to BallWorld.   You didn't realize it then, but the Timer object actually spawned a new thread that periodically called the actionPerformed() method of its ActionListeners.    This is why the application's buttons still worked when the animation was running and why the screen repainted on regular intervals.

This can be a tough lab for some and involves the integration of many concepts and techniques.   Do not hesitate to ask lots of questions and please use the various communications tools (e.g. discussion newsgroup) liberally!

Before you start, review the following sections in the Java Resources web site:

Java Applets

Threads in Java

Note: that this week's lab may not run in most browsers due to the lack of Java 2 support in the browsers.   See the info on how to get Java 2 applets to work properly in browsers with the correct plug-in.

Click here to see the documentation of the Neko applet

Click here to see a demo of the lab.

Getting Ready

  •  Create a cs150l10\cs150l10s1 and a cs150l10\Neko directory.
  •  Use StructureBuilder to create the classes, properties and method signatures (with empty bodies).  Be sure to get the packaging, inheritance, and implentation correct.
  •  You will need the LRStructure package.    Download it from Lab 6.   Put the whole package in the cs150l10 directory as normal.
  •  Add the code to any constructors that need it, to save any input parameters in their respective properties.
  •  Initialize any properties that you can to instances that make sense as default values.
  •  Write the code for the various accessor methods.
  • Go through the sections to the left in order.

Here's a neat applets that some people have written.   Our applet will be different than these, but still shares many similar ideas: 

http://www.svengato.com/neko.html

http://acs.senecac.on.ca/~michael/programs/java/neko1.1/neko.html

http://www.student.ipfw.edu/~parecl01/class/neko.htm

 

 

 

Laboratory written by Stephen Wong and Antonio Garcia