Lightweight components, introduced by JDK 1.1, offer several important advantages over traditional JDK 1.0-style components. For one, they are much more efficient than traditional components because they do not make use of native GUI peers, being instead a pure-Java kluge on top of the old AWT. More importantly for this particular application, however, is that these components are transparent. This means that a lightweight component can easily overlay information on top of another component.
We will use this transparency feature to implement our whiteboard; when the user selects a particular drawing tool then a lightweight component will be overlaid on the whiteboard. The drawing tool can then use this component to annotate the whiteboard display and collect GUI events.

The whiteboard in action
The following classes comprise the whiteboard:
WBLauncher -- A simple applet that launches the whiteboard when clicked.WB -- The main whiteboard class, which is a standalone Frame containing all of the whiteboard components.Tool -- An interface that provides access to all the whiteboard's drawing tools.Element -- An interface that describes the elements of a whiteboard drawing.WBContainer -- A lightweight container that displays the contents of the whiteboard.Rect -- A drawing tool that allows rectangles of various colors to be placed on the whiteboard.Select -- A drawing tool that allows existing elements of the whiteboard to be moved.ObservableList -- A class that maintains the list of elements comprising a whiteboard drawing. It is very similar to a Vector except that it notifies listeners whenever a change is made to the list.UpdateListener -- An interface that must be implemented by classes wishing to be notified when an ObservableList is modified.UpdateEvent -- An event that notifies of a change to an ObservableList; it is delivered through the ObservableList interface.LWContainer -- A generic lightweight container; a lightweight equivalent to the Panel class.LWImageButton -- A generic lightweight image button.
This may seem like a large number of classes, but the core of the whiteboard is, in fact, surprisingly small. The WB class contains the controlling logic of the whiteboard; the WBContainer class contains the display code; and the Tool and Element interfaces describe the various tools and elements.
Class WBLauncher
WBLauncher is a simple applet that provides a simple introductory interface to the whiteboard, delaying the download of the whiteboard's
classes until the user chooses to launch it.
CNC MachiningBy Anonymous on April 1, 2009, 5:29 pmI am searching what is the best choice (with java) to draw simple shapes (2d) and vectorize them to build G-Code in order to machine them later. ¿Opinions?
Reply | Read entire comment
View all comments