CSI Laboratory # 2


Due: Start of class at 11 a.m. on Tuesday, Feb 4


Objective: This lab is intended to introduce you to simple event-driven programming by making your No-Clicking sign from lab 1 responsive to actions the user performs with the mouse.

Preparation for Lab 2

  1. First you need to locate a free computer in either Wright 112 or 339. Once you have logged on, if you have not already changed your password, do so now! Follow the directions on the paper that contains your "User Name" and "Initial Password."
  2. Create a new folder "lab2" on the " Student Z: " drive in the folder "cs061" which you created in lab 1.
  3. Start Internet Explorer by Start | Programs | Internet | Internet Explorer and go to http://www.cs.uni.edu/~fienup/cs061f02/labs/lab2/.
  4. Download each of the files "objectdraw.jar", "lab_2.gpj", and "NoClicking2.java" by right-clicking on the name of each file and selecting "Save Target As". Save these files to your newly created "Z:\cs061\lab2" folder.
  5. Start jGrasp by double-clicking on the lab_2.gpj project file that you downloaded to your new lab2 folder. By using this project file you sets up the correct Compiler and run-time settings for the objectdraw package.
  6. Click on the "Project" tab at the bottom of the upper-left-hand sub-window of jGrasp. Double click "NoClicking2.java" file. Enlarge the NoClicking2.java" window .

The text we have placed in "NoClicking2.java" is just the skeleton of a complete Java program. We have included the header for the definition of a class "NoClicking" that extends "WindowController" and within this class we have typed headers for the event handling methods you will want to use during lab. You will want to cut and paste your "begin" method from lab 1 that constructs the "No Clicking" sign.

You should follow our lead and begin writing your program by typing comments rather than actual Java commands. Near the top of the file we have included a temporary comment telling you to enter your name, course-section time and the current date. Such identifying comments are always good practice, and in a class like this they make the grader's job much easier.

Making Your "No Clicking" Sign Responsive

In Lab 2 we want you to explore the mouse-event methods by having your "No Clicking" sign change with mouse actions. In particular, we want your program to:

  1. emphasize the sign's warning by making the word "CLICKING" bold when the user moves the mouse into the applet window. As indicated in the yellow "Quick Summary of Graphic Objects and Methods" handout, there is a "setBold" method which you can use to change the style of Text objects. There is also an obvious place to tell Java to make this change -- the "onMouseEnter" method. To make this possible, you will need to make an instance variable for the name of the Text object containing the word "CLICKING" and assign it a value when the Text object is constructed.
  2. return the word "CLICKING" to plain text when the mouse moves out of the applet window.
  3. have the circle and diagonal line through the text disappear while the user presses the mouse button. You can use the "hide" method to make these objects disappear.
  4. have the circle and diagonal line through the text reappear when the mouse is released. You can use the "show" method to make these objects re-appear.

Submitting Your Work

The submission procedure is as follows and will be basically the same every week.

These should be turned into the instructor inside the same large vanilla envelope as last week.