Gentle Introduction to GUI programming with Java and AWT

CSC 397 Lab Assignment 1

Assigned 3 September 1998

Due 14 September 1998

 

This is an individual assignment, but feel free to give and receive assistance.

Table of Contents.

Introduction

Summary of Chapter 1

JDK: the Java Development Kit

Lab Assignment

To Turn In

 

 

Introduction.

The basis for this assignment is the Click Counter program from Chapter 1 of Fintan Culwin's A Java GUI Programmer's Primer. The book was published by Prentice Hall earlier this year and can be purchased for $35, but the draft is available from his web site at South Bank University in London. The source code can easily be downloaded.

Browse through the contents of Chapter 1 (sections 1.1 through 1.7). Its purpose is to introduce structured methods for developing a GUI-based application. The key concepts are:

 

Summary of Chapter 1.

Section 1.1 describes the ClickCounter application class. Emphasis is on structure and behavior of ClickCounter objects, without regard for the UI. The Java course file ClickCounter.java can be downloaded from there.

Section 1.2 describes possible UI behaviors for ClickCounters, in the form of state transition diagrams. He uses notation from the Universal Modeling Language (UML). Text accompanying the first example, Figure 1.2, explains the notation. Figure 1.5 describes the UI behavior implemented by the code.

Section 1.3 is crucial to understanding the software design architecture. The system consists of three modules: the application module implements the ClickCounter class, the presentation module implements the graphical user interface, containing the visible parts, and the translation module implements the behavior of the interface.

Section 1.4 describes the ClickCounterPresentation class, which implements the presentation module. ClickCounterPresentation.java can be downloaded at the bottom of the page.

Section 1.5 describes the ClickCounterTranslation class, which implements the translation module. This is the applet, derived from the Applet class, whereas ClickCounter and ClickCounterPresentation are derived from Object. This is the controlling class, which is receives user input events and directs the presentation and application to respond appropriately. ClickCounterTranslation.java can be downloaded at the bottom of the page.

Section 1.6 shows simple HTML code to test the applet using a web browser. The .java files referenced above all contain java source code and must be compiled into bytecode (.class) files before the program can be run. JDK contains the Java compiler "javac" to do this. More on JDK later.

Section 1.7 describes running the applet as a stand-alone outside a browser. Given everything from above, this can be accomplished in JDK by invoking "java" with ClickCounterTranslation.class.

 

JDK: the Java Development Kit

JDK is installed in all Computer Science Department labs (209, 210, 213). You may also install it at home by either downloading it from Sun Microsystems web site, or by copying it from the \\eccentric\pubware\CS Zip Disk\jdk1.1.6 folder onto your own zip disk.

This is a suite of command line tools. You have to open up a DOS window to use them. For this assignment, you will need "javac" to compile java source files into bytecode, and "java" to interpret (execute) the bytecode outside of a web browser.

 

The Lab Assignment (100 points maximum; the more parts you do, the better your score)

1. After familiarizing yourself with Chapter 1 description of the Click Counter, download all the java files. Then compile and run the application both under control of a browser and as a standalone. The ClickCounterTranslation class contains the "main" method required for standalone execution (not required for execution from a browser, but can be present anyway). Be sure to save an extra copy for item 5, so you can start with a clean copy of the original code. (20 points)

2. You will notice that the counter has a small upper limit. Double its upper limit, and rerun the application to assure that it works properly. (5 points)

3. Modify the program from item 2 so that it increments and decrements by 2 rather than 1, and forces the upper limit to be an even number (if odd, add one). What changes did you have to make in which modules? (15 points)

4. Modify the program from item 3 to implement a circular counter. If decrement button is pressed when counter is 0, set counter to maximum value. If increment button is pressed when counter is at maximum value, set counter to 0. Buttons should therefore never be disabled. What changes did you have to make in which modules? How does this affect the state transition diagram representing UI behavior (original STD is in Section 1.2, Figure 1.5)? (20 points)

5. Modify the original program to implement a golf score keeper. The display area we currently have will show the number of strokes for the current hole (0-9; we'll play by my wife's rules!). Two additional digital display areas will be required: one to show the current hole number (1-18) and one to show the total number of strokes (0-162) for the current 18-hole round. The initial value for hole number is 1, and for total score is 0. For each stroke, the increment button is pressed. For cheating purposes, we retain the decrement button. Each time the reset button is pressed, the hole-stroke counter reading is added to the total-stroke counter, the hole-stroke counter reading is reset to 0, and the hole counter is incremented. After the score for the 18th hole is recorded, no more interaction can occur. Do any labeling, relabeling and positioning of UI objects necessary to assure usability. Also change class and member names to something appropriate to this new application. (25 points)

6. As it stands, the poor golfer has no control over the total-stroke counter and the hole counter! The hole-stroke counter has an effective "undo" feature in the decrement button. Implement an "undo" feature for the total-stroke counter and the hole counter. In this case, "undo" means to subtract the previous hole score from the total score and decrement the hole number. The "undo" should be repeatable! Suppose you record 6 on hole 1, 5 on hole 2, and 4 on hole 3. The total will be 15, and the hole will be 4. One "undo" will reset the total to 11 and the hole to 3. A second "undo" will reset the total to 6 and the hole to 2. A third "undo" will reset the total to 0 and the hole to 1 (and disable the "undo"). No need to "redo" (i.e., undo the undo). Be sure to design and position this button so it will not be confused with the existing buttons. Sketch the resulting state transition diagram. (15 points)

 

 

To turn in.

Written responses where required (items 3, 4 and 6).

Source code files from item 4 (in folder Counter) and item 6 (in folder Golf). If item 6 is not completed, submit code from item 5 in its place. Copy the folders into \\eccentric\upload\csc397\001\<your-ID>