Assignment # 4

"Kaleidescope"

Due: Monday, October 5th by midnight.

Deliverables: Email all files that you create to cis3931@cs.fsu.edu by the due date, including a journal/diary of the steps you went through during this assignment. Since many of the assignments involve writing Java applets it will greatly assist the grading of the assignments if you create HTML on your home page that includes the assignment's applets. Please include the web address of your applet in the journal/diary. Note that for assignments that require you to create source code yourself rather than type in existing code (like this one) you should take careful measures not to accidentally make your .java files world-readable within your HTML directory.

When emailing your files it can be problematic to faithfully re-create the file names. Here are detailed instructions that you can use for this and future assignments. If you use xi.cs.fsu.edu (which is running Solaris) you can create a single compress "tar" file that can then be emailed to cis3931@cs.fsu.edu.

cd location_of_P4_source
gnutar czvf ~/P4.tar.gz .

If you use an email client that supports attachments then you can just attach the file P4.tar.gz to your email submission. If you do not use an email client that supports attachments you will first have to convert the binary compressed "tar" file into a format suitable for an email message, such as uuencoding. Here is an example of encoding the P4.tar.gz file and sending it via a UNIX pipe to a mail client:

uuencode P4.tar.gz < P4.tar.gz | /usr/ucb/mail -s "P4.tar.gz" cis3931@cs.fsu.edu

If you choose to use some other operating system, such as Windows '95, Windows NT or Windows '98 be careful that you use a compression agent that correctly preserves both case sensitivity and the entire file name length, such as WinZip.

You will be asked to re-submit your assignment via email if the format you use is not correctly identified and/or formatted. Please do not email all the files separately.

Assignment:

As an introduction to the Java Applet environment you are to write two versions of an applet that performs some simple graphics operations and responds to mouse and keyboard events using two different event models.

Your solution will behave exactly like the two examples below. Two versions of the program are required, one that uses version 1.0 of the Abstract Windowing Toolkit (AWT) event model and the other that uses the newer version 1.1 AWT event model. Unfortunately many people that have Java-aware browsers still only use the 1.0 event model, while newer versions of browsers can run both the 1.0 and 1.1 event models. This means that for the indeterminate future you need to be aware of the different models, since any web-based Java code you write may require either event model.

Each of these applets behaves the same way. To run, click on the links above. Pressing any of the mouse buttons while inside the applet portion of the browser window will cause a series of multi-colored objects to be displayed, centered at the x,y location of your mouse click. Pressing any key will cause the type of object to change. The applet will cycle through the six basic graphic objects listed below. The seventh option will display all of the previous six objects. After that, the applet starts back displaying the first object. The types of objects are listed below, with a reference to the appropriate java.awt.Graphics methods:

  1. Circles - drawOval()
  2. Filled circles - fillOval()
  3. Boxes - drawRect()
  4. 3D Boxes - draw3DRect()
  5. Filled boxes - fillRect()
  6. Filled 3D boxes - fill3DRect()

Each of the six graphic objects, as demonstrated in the example applets above, should follow the same algorithm to render it's image on the screen:

  1. Select a random number between 2 and 32 for the number of iterations (use java.lang.Math.random()).
  2. Select a random number between 2 and 32 for the width of the concentric drawings.
  3. Iterate using the selected iteration random number:

Applet writing can be done using a non-object oriented approach by placing all the code in a single class that is an extension of the Applet class, but you should continue to develop your object-oriented skills in this program. For this assignment you are required to create your applet with four classes:

  1. abstract class Drawings - include methods and member variables that can be used to manage both circles and boxes (for instance, your random number generator and color creation routines).
  2. class Circles extends Drawings - include methods and member variables to draw filled and outline circles.
  3. class Boxes extends Drawings - include methods and member variables to draw boxes, 3D boxes, filled boxes and filled 3D boxes.
  4. public class kScope extends java.applet.Applet - include methods and member variables to run the applet. At a minimum, you need to write the following methods (reference the overridden Applet methods):

In addition to the basic applet methods, you need to override the applet routines that are used to grab keyboard and mouse click events. As previously mentioned, the event models differ significantly between version 1.0 and 1.1 and you should create two separate applets, one that uses each model. For the version 1.0 event model, you need to override the following methods within the kScope class:

You also need to import java.applet.Applet and java.awt.*.

For the 1.1 event model, you need to override the following methods:

You also need to import java.applet.Applet, java.awt.* and java.awt.event.*.

Finally, use the following representative HTML to test out your code. You can assume your applet has a 512 by 512 region of the web page to use. While testing, pay attention to the output messages from your overridden methods that show up in the Java console, especially when each message is invoked as you leave the page, return, minimize the window, resize the window, cover up and bring the window to the foreground, etc.

<HTML>
<HEAD>
<TITLE>Kaleidescope Applet</TITLE>
</HEAD>
<BODY>
<P><APPLET CODE="kScope.class" WIDTH=512 HEIGHT=512>
</APPLET></P>
</BODY>
</HTML>

Extra Credit points will be awarded for applets that go beyond these specific requirements. As an example, you could choose to interpret different key values to perform different tasks, add other graphic objects into the list, etc.