More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?

Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Examining HotSpot, an object-oriented drawing program

Learn how the pieces of the Java language and class library fit together through a study of this Java program

After spending several months looking at the parts of a system one piece at a time here in the in How To Java column, it's time to learn how to put them together and actually build something. The result is HotSpot.

This month we'll build on several subjects covered in prior columns -- including graphics, observers and observables, events, and components and containers.

The application

HotSpot is a simple, object-oriented drawing program. A drawing program allows a user to create a picture from a palette of simple geometric shapes. Once a shape has been placed on the drawing surface, the user can reselect it and adjust its size, shape, and position. In this respect, a drawing program differs from a paint program, in which a shape, once placed on the drawing surface, becomes nothing more than a colored collection of pixels.

Figure 1 shows a typical HotSpot drawing surface or "canvas." This canvas holds a single shape -- a square -- which has small gray boxes at its corners and center. These boxes are called hot spots, and they allow the user to manipulate the square.


Figure 1: A HotSpot canvas


Figure 2 illustrates the role hot spots play. The user selects a specific shape on the canvas by positioning the mouse over one of the hot spots and clicking on it. The user can then adjust the shape, size, and position of the selection by dragging the hot spot with the mouse.


Figure 2: Interaction with a HotSpot shape


The program HotSpot was named, obviously, after these hot spots. In keeping with the principles of object-oriented software design, each of the major components of the HotSpot program is represented by a Java language class. This set of components includes the canvas, the shapes, and even the hot spots.

Table 1 lists the classes that make up the HotSpot program. Class Shape and its subclasses represent the types of shapes that can be placed on a canvas. A Shape object contains a list of HotSpot objects that represent that shape's hot spots. Shape objects are managed by a ShapeMgr object, which is nothing more than a fancy subclass of class Canvas. The ShapeMgr object plays two roles: It manages a list of shapes and provides a place for them to draw themselves. The ShapeMgr object contains a HotSpotMgr object. In a manner similar to that of the ShapeMgr object, the HotSpotMgr object manages a list of HotSpot objects and also provides a convenient mechanism for locating the hot spot at a particular set of coordinates.



Shape public abstract class Shape implements Observer
RectangleShape public class RectangleShape extends Shape implements Observer
OvalShape public class OvalShape extends Shape implements Observer
LineShape public class LineShape extends Shape implements Observer
HotSpot public class HotSpot extends Observable
ShapeMgr public class ShapeMgr extends Canvas
HotSpotMgr public class HotSpotMgr
Main public class Main extends Applet
Dimensions public class Dimensions
Coordinates public class Coordinates


The pieces

By now two things should be obvious. First, HotSpot is not a particularly revolutionary drawing program. Second, a lot of thought was put into the design of HotSpot to ensure that it effectively demonstrates the material introduced in prior How To Java columns.

Resources