Project 6 - JavaBeans with Swing/AWT GUI Components
 Due Dec. 10, 6:00PM

You are going to implement a drawing package using the Java Swing library, which is built on top of the Abstract Windowing Toolkit (AWT). The program will manage a GUI (graphical user interface) consisting of a single window on a user's workstation/PC, taking input from a mouse to add and delete graphical objects from the window.

The handling of mouse events should use the JavaBeans event model, employing delegation to separate the code handling input (mouse) events from the code implementing the drawing routines.

On startup, your program should display a window containing a blank drawing area, and buttons or menus to select the various objects the user may draw.  The window should be half the size of the user's display. You get to choose whether to use buttons or pulldown menus to allow selection of the various types of objects to draw. If you use buttons, use text to label each button with the mode that is selected by that button. With either buttons or a menu, only one type of object can be selected at a time, and objects of that type are drawn until a different object type is selected by the user. The current mode (which type object is being drawn, and other associated attributes like color, fill, etc.) must always be obvious, either by highlighting the currently selected button, or displaying or highlighting the current mode selected via a menu.

The objects that can be drawn are:

For all these objects, selecting points with the mouse is done via mouse clicks (no dragging with the mouse button depressed). In addition, all objects can be one of four colors: black, blue, green, or red (for rectangles and polygons, that means the border of the object is that color). As for the object types, you must allow the user to select the current color of objects to be drawn, either via buttons or pulldown menus.

Rectangles and polygons can also be filled when drawn. This means that there must be a way to select the current fill color for objects that can be filled, again either via buttons or a pulldown menu. The fill color can be one of the four colors for object borders (black, blue, green or red), or the user can specify using no fill.

Moving, copying, deleting and grouping objects

Your program must also allow the user to select one or more displayed objects, that can then be moved, copied, deleted or grouped. This means that in addition to buttons or menu entries for drawing the various object types, you must also have buttons or menu entries for moving, copying, deleting and grouping/ungrouping objects.

For all of these operations, selection of objects is done with left mouse clicks, sometimes combined with the Control (Ctrl) key for the grouping operation.  A left mouse click on an object selects that object, deselecting any previously selected objects.  A left mouse click on an unoccupied portion of the display window should deselect all objects, so that no object is selected.  To select more than one object, the Ctrl key should be pressed while performing a left mouse click.  Such an action toggles the selection of the object clicked on, meaning that if the object is not currently selected it becomes part of the currently selected set of objects, and if the object was already selected it becomes deselected.  The simplest strategy for deciding which object is being selected with each mouse click is to find one whose bounding box contains the current mouse position (if multiple objects enclose the position, any one can be selected). Also, changing to a different mode (e.g., to draw an object) deselects all currently selected objects.

When the delete mode is selected by the user, left mouse clicks are used (ignoring the Ctrl key) to select the object to be deleted. A right mouse click then removes the selected object from the display. The delete operation can only be applied to a single object.

When the move mode is selected by the user, left mouse clicks are used to select the object to be moved, just as in delete mode. A right mouse click then determines the new placement of the object.  The move operation can only be applied to a single object.

When the copy mode is selected by the user, left mouse clicks are used to select the object to be copied. A right mouse click then determines the placement of the copy of the object. The copy operation can only be applied to a single object.

When the group mode is selected by the user, left mouse clicks are used (including with the Ctrl key, as described above) to select the objects to be grouped.  A right mouse click then groups the selected objects into a single new object that can then be deleted, moved, copied or grouped again with other objects.  Note that a straightforward implementation of operations on a group of objects would pass the operations through to each object in the group (recursively if groups are nested).

When the ungroup mode is selected by the user, left mouse clicks are used to select the object to be ungrouped.  A right mouse click then ungroups the selected object, effectively undoing the group operation that created it. Applying the ungroup operation to a non-grouped object has no effect.  The ungroup operation can only be applied to a single object.

While simply drawing objects on the display does not require storing all the information for the objects in your program, moving, copying, deleting and grouping/ungrouping objects does require storing this information. So you will need some data structure to keep track of all the objects that are currently displayed, and the data structure will need to be searched to find the objects that are being selected for a move, copy, delete or group/ungroup operation.

Exiting the program

Finally, one additional button or menu entry is required to allow the user to exit your drawing program. Providing a confirmation message before exiting (e.g., "Do you really want to exit? (y or n)''), to allow the user to change his/her mind, is required.

Swing/AWT Notes

A short tutorial for Swing is on the Sun developers web site, and a more extensive tutorial is on the main Sun Java web site.
A short tutorial for the Abstract Windowing Toolkit (AWT), which underlies Swing and which you may also need to use directly, is also on the Sun developers web site.

The APIs for Swing and AWT are available with the Java 1.3 API, under javax.swing and java.awt, respectively

Instructions for submitting your work

 

Web Accessibility