Java Reference
In-Depth Information
Listing 2.1 Contents of existing paint program's JAR file
META-INF/
META-INF/MANIFEST.MF
org/
org/foo/
org/foo/paint/
org/foo/paint/PaintFrame$1$1.class
org/foo/paint/PaintFrame$1.class
org/foo/paint/PaintFrame$ShapeActionListener.class
org/foo/paint/PaintFrame.class
org/foo/paint/SimpleShape.class
org/foo/paint/ShapeComponent.class
org/foo/shape/
org/foo/shape/Circle.class
org/foo/shape/circle.png
org/foo/shape/Square.class
org/foo/shape/square.png
org/foo/shape/Triangle.class
org/foo/shape/triangle.png
The listing begins with a standard manifest file. Then come the application classes,
followed by various shape implementations.
The main classes composing the paint program are described in table 2.1.
Table 2.1
Overview of the classes in the paint program
Class
Description
The main window of the paint program, which contains the
toolbar and drawing canvas. It also has a static main()
method to launch the program.
org.foo.paint.PaintFrame
An interface representing an abstract shape for painting.
org.foo.paint.SimpleShape
org.foo.paint.ShapeComponent A GUI component responsible for drawing shapes onto the
drawing canvas.
An implementation of SimpleShape for drawing circles.
org.foo.shape.Circle
org.foo.shape.Square
An implementation of SimpleShape for drawing squares.
org.foo.shape.Triangle
An implementation of SimpleShape for drawing triangles.
For those familiar with Swing, PaintFrame extends JFrame and contains a JToolBar
and a JPanel canvas. PaintFrame maintains a list of available SimpleShape implemen-
tations, which it displays in the toolbar. When the user selects a shape in the toolbar
and clicks in the canvas to draw the shape, a ShapeComponent (which extends JCompo-
nent ) is added to the canvas at the location where the user clicked. A ShapeComponent
is associated with a specific SimpleShape implementation by name, which it retrieves
from a reference to its PaintFrame . Figure 2.4 highlights some of the UI elements in
the paint program GUI .
 
Search WWH ::




Custom Search