HCI-631 Project #1:
An XML-based Interface Construction System
Due: Noon on Thursday, 5 September
This project asks you to create a user interface made up of common GUI widgets under the direction of a driver program provided to you. The provided driver reads an XML-based interface definition from a file and translates this into method calls on a class that you create. An example interface definition and the resulting interface might look like this:
|
<?xml version="1.0" encoding="UTF-8"?> <interface> <label text="The Title" x="10" y="10" w="100" h="20"/> <separator x="40" y="10" w="100" h="3"/> <button name="btn1" label="A Button" x="50" y="10" w="100" h="20"/> <exit-button name="exit" label="Exit" x="80" y="10" w="100" h="20"/> </interface> |
To complete this project, you need to provide a class named
UICreator in the hci631.project1
package. This class should be a sub-class of the abstract
class Creator, which requires you to implement
the methods shown in the table below. We also provide you with
the source file of Creator, which contains comments and other
useful information.
| Method | Comment |
|---|---|
void addButton( String sName, String sLabel,
Rectangle rBounds ) |
Add a button to the interface with label sLabel and the bounding box specified by rBounds. |
void addExitButton( String sName, String sLabel,
Rectangle rBounds ) |
Add a button to the interface that exits the program, with label sLabel and the bounding box specified by rBounds. |
void addChoice( String sName, String[] sItems,
Rectangle rBounds ) |
Add a combo box to the interface containing the items in sItems with the bounding box specified by rBounds. |
void addLabel( String sText,
Rectangle rBounds ) |
Add a label to the interface with the text sText centered in the bounding box specified by rBounds. |
void addScrollbar( String sName, int nMin, int nMax,
Rectangle rBounds ) |
Add a horizontal scrollbar to the interface with values bounded by nMin and nMax. The scrollbar should fill the bounding box specified by rBounds. |
void addSeparator( Rectangle rBounds ) |
Add a horizontal separator to the interface bounded by rBounds. |
void finished() |
Called when the driver is finished adding interface elements so that your class can finish layout and display the window containing the interface. |
To complete your UICreator class, you will need
to provide implementations for each of the abstract methods in
Creator. Each of the add*() methods
will be called to specify an interface item that is to be
added to your interface. Each of these items corresponds to a
component that is already available for you in the
javax.swing package, as shown in the table below.
| Method | Component | Comment |
|---|---|---|
addButton |
javax.swing.JButton |
|
addChoice |
javax.swing.JComboBox |
Use an uneditable ComboBox. |
addExitButton |
javax.swing.JButton |
Clicking on this button should cause your program to
exit using the method System.exit(0). |
addLabel |
javax.swing.JLabel |
Text should be center justified. |
addScrollbar |
javax.swing.JScrollBar |
Scrollbar should have a horizontal orientation. |
addSeparator |
javax.swing.JSeparator |
Separator should have a horizontal orientation. |
The finished() method is called to inform you
that all of the interface items have been given (which should
be your signal to do any final layout or sizing that is needed).
In addition to implementing the abstract methods in
Creator, your UICreator will also
need to have a constructor with the following signature:
public UICreator( JFrame pFrame )
The constructor will be invoked initially to provide you with
a JFrame, the window in which you should display
your components. Note that this JFrame is also a required
parameter for the constructor of the Creator
super-class, so you will need to call super( pFrame
) as the first line of the UICreator
constructor. You will construct your interface by adding
components to the content pane of the JFrame with
the add method
(e.g. JFrame.getContentPane.add( component
)). You should arrange for all of the components to be
(potentially) visible in the final interface by resizing the
JFrame using the setSize() method,
or providing a mechanism to scroll through the items (possibly
using a javax.swing.JScrollPane).
Once the interface has been constructed, your class should
arrange to have it execute properly. In this case, you will
need to create a Listener object for each of the
interactive components that you create (Buttons, ComboBoxes,
and ScrollBars). Each listener should call the
outputString() method of Creator to
output a text string that contains the name of the component
and its current state. The table below shows the type of
listener to use for each component and the format of the
string that should be outputted by the listener. NOTE:
Do not use System.out.println() to output
a text string for this purpose and also do not use
outputString() to output other text strings that
are not in the format described below. This will
circumvent/interfere with the grading process and result in a lower
grade for you!
| Component | Listener | Example String |
|---|---|---|
javax.swing.JButton |
java.awt.event.ActionListener |
btn_name: pressed! |
javax.swing.JComboBox |
java.awt.event.ActionListener |
box_name: item1 selected! |
javax.swing.JScrollBar |
java.awt.event.AdjustmentListener |
scrollbar_name: moved to 15 |
Resources
This project should
be done using the Java 2 SDK version 1.4, which can be
downloaded from here.
You may also do the project with earlier versions of the Java
2 development environment, provided you download and install
the Java API for XML Processing (JAXP) from here. You
can also find documentation for the Java toolkit and a Java
tutorial on the java website at http://java.sun.com. See the
course syllabus for more information on learning about Java
and for Java development environments.
The source code for the Driver and
Creator classes, a starting point for your
UICreator class, and several sample XML files can be downloaded from http://www.cs.cmu.edu/~jeffreyn/class/05-631/proj1/code/.
In addition, a sample executable can be downloaded from that
location (in UICreator.jar).
Turning Your Program In
Your program is due at noon on Thursday, 5 September. You
should turn in your assignment via e-mail to
jeffreyn@cs.cmu.edu whose
subject contains the string "631 project1 turnin for " and
then your Andrew ID. What you turn in should take the form of a
single "zip" file (as an attachment to your e-mail message)
that contains the source code (UICreator.java)
for your UICreator class and any needed support
classes. Do not send multiple attached files (i.e., one
attachment for each source file). Again, be certain to include
the string "631 project1 turnin for " and then your Andrew ID, in
the subject of your message.
Grading
Your program will be compiled and run on my machine against
test cases unknown to you. If your program performs properly,
is well-structured, and is copiously documented you will
receive 92 out of 100 points (a low A). To receive additional
points you need to do something "extra" of your own design
that improves the program in some way. The available "extra"
points will be allocated by comparing and subjectively ranking
all the additional features turned in (8 points will go to the
best program(s), 6 points to others, 4 points to others, and
at least 2 points to the rest). Please describe any "extra"
features that you have included in your turn in e-mail
message. If you need to change the driver class in order to
implement your extra features, please tell me about this when
you turn in your program and include modified source for the
driver in your zip file. NOTE: The driver should remain
compatible with the existing XML files (i.e., it may extend
the current format but not change it) so the same test
framework can be used.
The tentative detailed grading breakdown for this assignment is as follows:
| Basics: Turned in and compiles | 25 pts | No Crashes | 15 pts |
| Good Commenting | 10 pts | Exit works | 5 pts |
| Interactive Components Work (3) | 5 pts each | No Crashes | 15 pts |
| Various Test Cases | 2-5 pts each |
Test cases will be designed to test base functionality as well as boundary conditions. Comments in your code should document each class, method, variable, and parameter, as well as provide comments need to understand the logic within the body of the code. Please use JavaDoc comments where appropriate. Format your code to be readable (e.g., use indentation) and to make it easy to find methods and other declarations (e.g., via white space and/or explicit separators).