Assignment # 5

"Komponent Kaleidescope"

Due: Monday, October 19th 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_P5_source
gnutar czvf ~/P5.tar.gz .

If you use an email client that supports attachments then you can just attach the file P5.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 P5.tar.gz file and sending it via a UNIX pipe to a mail client:

uuencode P5.tar.gz < P5.tar.gz | /usr/ucb/mail -s "P5.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:

This assignment builds on your previous assignment. In particular, you will use some of the Abstract Windowing Toolkit (AWT) components. Read Chapter 18 of the book or the on-line tutorial (Overview of the Java UI) and Chapter 19 (Using Components, the GUI Building Blocks). As you may discover in any future employment, you are often asked to modify an existing program to correct bugs or enhance the functionality. In this assignment you will use as your starting place an already-working Java program featured in Chapter 18. It creates many of the basic AWT controls (buttons, checkboxes, choices, lists, menus and text fields). Your job is to modify the program according to the rules below:

  1. Obtain a copy of the Java application GUIWindow.java. It is also featured in Chapter 18 of the book.
  2. Modify the Canvas code so that rather than containing a line with three labeled points it contains your solution to the previous programming assignment (your Kaleidescope applet). Hint: extend the Canvas instead of the Applet class. Use the 1.1 event model. Keep the mouse event code but remove the keyboard event code that was used to switch between objects (you will use an AWT List component to select the object to draw).
  3. Change the TextArea label to say "Log of events". Change the background color of the TextArea to blue and the foreground to yellow. Change the TextArea so it is not editable by the user. You will be using this area to print out log entries of how your different component event handlers behave. Run the example solution below to see how it works.
  4. Modify the menu options in the following manner:
    1. Change the name of the menu to "Options Menu".
    2. Change the first menu option to read "Spawn new Window". Initially make it disabled. When it is enabled and the user selects this menu option, have your program create another copy of the window ("spawn" another copy of itself).
    3. Change the second menu option to "Enable Spawn Menu Option" and make it toggle the first menu option as disabled or enabled.
    4. Change the third menu option to "Exit" and make it exit the application when selected.
    5. Change the fifth menu option to "File dialog box". Change the file dialog behavior to match the example below (it logs the file name if one is selected or the word "canceled" if CANCEL selected).
  5. Change the TextField so that it is longer and has no initial text string placed in it. When a user places text in the field and presses RETURN, print out the string in the log window and then highlight the text (run the example and watch how it behaves).
  6. Change the Button name to "Clear Log" (in red). When this button is selected, clear out the TextArea (clear the on-screen log).
  7. Change the Checkbox name to "Enable Object Selection". Make it initially not checked. When not checked, the List is disabled. When checked, the List is enabled.
  8. Change the Choice popup list to select the background color of your Canvas (Kaleidescope). The choices will be: Black, Green, Blue, Red, Yellow, Cyan, and Magenta. Make the default background color be Black.
  9. Change the List items to display the possible list of objects your Kaleidescope code handles. At a minimum, this list would include: Circles, Filled Circles, Boxes, 3D Boxes, Filled Boxes, Filled 3D Boxes and Kaleidescope (all the above). Let Circles be the default list selection.
  10. When in doubt, refer to the working solution example below. Try to get your program to "look and feel" like this solution. Make sure you try all the various menu, list, button, etc. options so you understand how they work. Pay attention to the various colors assigned to different components and make sure they match.
  11. The bulk of this assignment is figuring out how to handle events for the various components. The "How to use ..." sections of Chapter 19 provide examples and explanations.

You can run the original GUIWindow program by selecting the link below. It behaves exactly like the sample from the on-line tutorial of Chapter 18.

Original version:

Source code to the original version is in GUIWindow.java. Source code to the AppletButton class, used to fire up both of these applications as a separate window, can be found in AppletButton.java, although you do not have to modify this file nor really understand how it works for this assignment (although it might be fun to try and figure out how this code works!).

To help you make sure your program is a correct solution to the set of rules above you can run this modified version of GUIWindow. It represents a correct solution to the assignment.

Modified version:

A helpful hint while programming and debugging -- this program will run as a stand-alone Java application and does not need to be fired up via the AppletButton applet in a browser. A common "edit/compile/run" cycle would look like this:

edit GUIWindow.java
javac GUIWindow.java
java GUIWindow