Class Graphics2DTest

java.lang.Object
  extended byGraphics2DTest
Direct Known Subclasses:
Graphics2DTestPlusButton, Graphics2DTestPlusUserDrawing

public class Graphics2DTest
extends java.lang.Object

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

canvas

protected static Graphics2DTest.DrawingCanvas canvas
The drawing canvas


shapeList

protected static java.util.Vector shapeList
Collection of RectShape objects to draw on the canvas.


x

protected static int x
Successive x position of added rects


y

protected static int y
Successive y position of added rects


frame

protected static javax.swing.JFrame frame
Outermost display window


vbox

protected static javax.swing.Box vbox
Inner box of display window


buttonBox

protected static javax.swing.Box buttonBox
Box for row of buttons at bottom of display


addButton

protected static javax.swing.JButton addButton
The add rect button


delButton

protected static javax.swing.JButton delButton
The delete rect button


numButton

protected static javax.swing.JButton numButton
The number of rects button

Constructor Detail

Graphics2DTest

public Graphics2DTest()
Method Detail

compose

public static void compose()
Construct and compose the window contents, which is comprised of the scrolling drawing canvas and the bottom row of buttons.


addButtonListeners

protected static void addButtonListeners(javax.swing.JButton addButton,
                                         javax.swing.JButton delButton,
                                         javax.swing.JButton numButton)

main

public static void main(java.lang.String[] args)
Just call the compose method to do all of the work.