Graphical user interfaces
Exercise 2, Friday 2.11.2007


WWW-links

Instructions

This time we shall not use NetBeans (or other tool) to create the GUI by dragging the components. Instead, we'll write the GUI code ourself. You may, however, use an IDE for editing and testing.

Take file x1_skeleton.java from course examples page, rename it to username.java, where username is your cs username. Further, rename the class to your username too. Other than CS major students, I'll let you know what to use.

The skeleton contains some useful functions (that do all the non-GUI functionality), e.g., read a file of tooltips (example at www-page) and actually evaluate the expression. The evaluation of the expression uses new scripting feature, thus it requires Java 1.6 or later.

X exercises are obligatory personal exercises

The answers to X-exercises have to be unique for every student. Not even partial copies of the same answer are allowed. The answer has to be sent via email by Thursday 2:00 pm (the previous day) according to the instructions below. You will receive an acknowledgment upon successful processing within few minutes. Answers will be graded. The answer must also contain a short self-evaluation in which you describe whether the program works, nearly works, or does not probably work; how good structure is has, what could be improved, etc. The self-evaluation must be stored as a comment within the program. A correct and proper self-evaluation is worth one point (in case of a proper answer).

How to submit

Send your answer to using cs to user sjuva with a subject GUI_X1_username (case-sensitive, with underscores, username is your username), and the answer (with self-evaluation) as the body of the message (no attachments). Most reliably using program mail at cs:

/usr/ucb/mail -s GUI_X1_username sjuva < username.java

where username is your cs username and username.java is the single source file containing your answer. This first X-exercise is also a rehearsal and a test of the automatic processing system.

Other than CS majors will get separate instructions.

X1. Calculator

Make a simple calculator that can be used with both mouse and keyboard.

The user can type in an expression (like "1+1") using either mouse clicking the visible calculator buttons, or by typing the expression with keyboard (i.e., both should work). The keyboard should be active all the time (i.e., no focus outside display).

Whenever the user presses the = button, the expression in display is evaluated and placed to the display. Button <- removes the last character, C clears to display (set to "0"). Other keys add the characted to the display.

For the last 2 points, make Enter -key to evaluate expression (like = button) and Escape -key to clear display (like C button). There are hints to implement this in the code skeleton.

Example implementation (.class) at examples page. Use Java6 to run.

3. Drag and drop memory window

Notice, this is a normal exercise, do not submit by email beforehand.

Create an additional Java class that implements memory functionality for the calculator. Memory consists is 5 slots (text fields). The user can drag and drop (hold with mouse button and move) display content from calculator to a memory slot, or vice versa.

In addition to implementing the memory class, you need to add DnD support for calculator display.

Memory can be used as a stand-alone application, or started from the calculator application.

Example implementation, code skeleton with hints, a helper class (TextFieldMouseAdapter) and example DnD application at www-page.

Consider also the following questions:


Last modified SJ