|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectGraphics2DTest
Class Graphics2DTest is a simple example of drawing on and updating a Graphics2D display. It displays a background image and allows the user to add and delete rectangles from the drawing. It also adds a mouse listener that reports when and where a mouse press happens.
The Java tutorial on 2D graphics covers all the details of how to use the Graphics2d and Graphics classes. The Java tutorial on "How to Write a Mouse Listener" covers the subject of mouse listeners.
Nested Class Summary | |
static class |
Graphics2DTest.DrawingCanvas
Class DrawingCanvas defines a drawing canvas as a JPanel with a specialized paint method. |
static class |
Graphics2DTest.MousePressedListener
Class MousePressedListener implements a mouse listener for press events only, ignoring all other events. |
static class |
Graphics2DTest.RectShape
Class RectShape defines the model datatype for a rectangle as an x/y position and a width/height. |
Field Summary | |
protected static javax.swing.JButton |
addButton
The add rect button |
protected static javax.swing.Box |
buttonBox
Box for row of buttons at bottom of display |
protected static Graphics2DTest.DrawingCanvas |
canvas
The drawing canvas |
protected static javax.swing.JButton |
delButton
The delete rect button |
protected static javax.swing.JFrame |
frame
Outermost display window |
protected static javax.swing.JButton |
numButton
The number of rects button |
protected static java.util.Vector |
shapeList
Collection of RectShape objects to draw on the canvas. |
protected static javax.swing.Box |
vbox
Inner box of display window |
protected static int |
x
Successive x position of added rects |
protected static int |
y
Successive y position of added rects |
Constructor Summary | |
Graphics2DTest()
|
Method Summary | |
protected static void |
addButtonListeners(javax.swing.JButton addButton,
javax.swing.JButton delButton,
javax.swing.JButton numButton)
|
static void |
compose()
Construct and compose the window contents, which is comprised of the scrolling drawing canvas and the bottom row of buttons. |
static void |
main(java.lang.String[] args)
Just call the compose method to do all of the work. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static Graphics2DTest.DrawingCanvas canvas
protected static java.util.Vector shapeList
protected static int x
protected static int y
protected static javax.swing.JFrame frame
protected static javax.swing.Box vbox
protected static javax.swing.Box buttonBox
protected static javax.swing.JButton addButton
protected static javax.swing.JButton delButton
protected static javax.swing.JButton numButton
Constructor Detail |
public Graphics2DTest()
Method Detail |
public static void compose()
protected static void addButtonListeners(javax.swing.JButton addButton, javax.swing.JButton delButton, javax.swing.JButton numButton)
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |