| |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Window | +--java.awt.Frame | +--CSLib.ClosableFrame | +--CSLib.DrawingBox
DrawingBox
is a frame upon which many of the
java.awt.Graphics
operations can be performed. As a
frame, it exists as a separate window, and the operations on it may be
performed from anywhere -- not just from within a paint
method (as is normal with a frame's Graphics
object).
(However, to be used effectively as a teaching aid, operations on a
DrawingBox
should be performed from within
a single method, which later can be converted to a paint
method.)
Care must be taken that when this frame is obscured, that
subsequently it can repaint itself. An off-screen Graphics
context keeps an up-to-date copy of this frame's Graphics
at all times. The origin of the coordinate system is translated so that
it is in the upper left of the drawable portion of the
frame. Consequently, DrawingBox
behaves more like a
Canvas
object that occupies the drawable portion of a frame.
In order to distinguish the Frame
from its drawable portion,
methods getDrawableWidth
and getDrawableHeight
are provided.
DrawingBox
uses inner classes DBMouseAdapter
(extending java.awt.event.MouseAdapter
) to implement mouse
listeners, and DBMouseMotionAdapter
(extending
java.awt.event.MouseMotionAdapter
) to implement mouse
motion listeners.
Inner Class Summary | |
public class | DrawingBox.DBMouseAdapterDBMouseAdapter is an inner class that implements
the Mouse listener for DrawingBox . |
public class | DrawingBox.DBMouseMotionAdapterDBMouseMotionAdapter is an inner class that implements
the Mouse motion listener for DrawingBox . |
Field Summary | |
(package private) Dimension | screenSize the size of the user's screen |
Fields inherited from class java.awt.Frame |
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, NORMAL, ICONIFIED |
Fields inherited from class java.awt.Component |
TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT |
Constructor Summary | |
DrawingBox() Constructs a DrawingBox with the default title. | |
DrawingBox(String title) Constructs a DrawingBox with a specific title. |
Method Summary | |
void | clear() Clears the entire drawing box. |
void | clearRect(int x, int y, int width, int height) Clears the specified rectangle by filling it with the background color of the current drawing box. |
void | drawCircle(int x, int y, int radius) Draws the outline of a circle. |
void | drawCircle(Point p, int radius) Draws the outline of a circle. |
void | drawImage(Image img, int x, int y) Draws the specified image with its top-left corner at (x,y) in this drawing box's coordinate system. |
void | drawLine(int x1, int x2, int y1, int y2) Draws a line, using the current color, between the points (x1,y1) and (x2,y2) in this drawing box's coordinate system. |
void | drawOval(int x1, int y1, int width, int height) Draws the outline of an oval. |
void | drawRect(int x, int y, int width, int height) Draws the outline of the specified rectangle. |
void | drawRect(Rectangle r) Draws the outline of the specified rectangle given a Rectangle object. |
void | drawString(String str, int x, int y) Draws the text given by the specified string, using this drawing box's current font and color. |
void | fillCircle(int x, int y, int radius) Fills a circle with center at (x,y) and with a given radius using this drawing box's current color. |
void | fillCircle(Point p, int radius) Fills a circle with center at point p and with a given radius, using this drawing box's current color. |
void | fillOval(int x1, int y1, int width, int height) Fills an oval bounded by the specified rectangle with this drawing box's current color. |
void | fillRect(int x, int y, int width, int height) Fills the specified rectangle. |
void | fillRect(Rectangle r) Fills the specified rectangle given a Rectangle object. |
Color | getColor() Gets this drawing box's current color. |
int | getDrawableHeight() Returns the current drawable height (less insets) of this drawing box. |
int | getDrawableWidth() Returns the current drawable width (less insets) of this drawing box. |
void | paint(Graphics g) Paints the drawing box. |
void | setColor(Color c) Sets this drawing box's color. |
void | setDrawableSize(int width, int height) Sets the drawable size of this drawing box by setting a smaller size, then increasing it by the amount of the insets. |
Methods inherited from class CSLib.ClosableFrame |
windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened |
Methods inherited from class java.awt.Frame |
addNotify, getTitle, setTitle, getIconImage, setIconImage, getMenuBar, setMenuBar, isResizable, setResizable, setState, getState, remove, removeNotify, setCursor, getCursorType, getFrames, getAccessibleContext |
Methods inherited from class java.awt.Window |
pack, show, hide, dispose, toFront, toBack, getToolkit, getWarningString, getLocale, getInputContext, setCursor, getOwner, getOwnedWindows, addWindowListener, removeWindowListener, getListeners, getFocusOwner, postEvent, isShowing, applyResourceBundle, applyResourceBundle, getGraphicsConfiguration |
Methods inherited from class java.awt.Container |
getComponentCount, countComponents, getComponent, getComponents, getInsets, insets, add, add, add, add, add, remove, remove, removeAll, getLayout, setLayout, doLayout, layout, invalidate, validate, setFont, getPreferredSize, preferredSize, getMinimumSize, minimumSize, getMaximumSize, getAlignmentX, getAlignmentY, update, print, paintComponents, printComponents, addContainerListener, removeContainerListener, deliverEvent, getComponentAt, locate, getComponentAt, findComponentAt, findComponentAt, isAncestorOf, list, list |
Methods inherited from class java.awt.Component |
getName, setName, getParent, getPeer, setDropTarget, getDropTarget, getTreeLock, isValid, isDisplayable, isVisible, isEnabled, setEnabled, enable, enable, disable, isDoubleBuffered, enableInputMethods, setVisible, show, getForeground, setForeground, getBackground, setBackground, getFont, setLocale, getColorModel, getLocation, getLocationOnScreen, location, setLocation, move, setLocation, getSize, size, setSize, resize, setSize, resize, getBounds, bounds, setBounds, reshape, setBounds, getX, getY, getWidth, getHeight, getBounds, getSize, getLocation, isOpaque, isLightweight, getGraphics, getFontMetrics, getCursor, paintAll, repaint, repaint, repaint, repaint, printAll, imageUpdate, createImage, createImage, prepareImage, prepareImage, checkImage, checkImage, contains, inside, contains, dispatchEvent, addComponentListener, removeComponentListener, addFocusListener, removeFocusListener, addHierarchyListener, removeHierarchyListener, addHierarchyBoundsListener, removeHierarchyBoundsListener, addKeyListener, removeKeyListener, addMouseListener, removeMouseListener, addMouseMotionListener, removeMouseMotionListener, addInputMethodListener, removeInputMethodListener, getInputMethodRequests, handleEvent, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, action, gotFocus, lostFocus, isFocusTraversable, requestFocus, transferFocus, nextFocus, hasFocus, add, toString, list, list, list, addPropertyChangeListener, removePropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, setComponentOrientation, getComponentOrientation |
Methods inherited from class java.lang.Object |
getClass, hashCode, equals, notify, notifyAll, wait, wait, wait |
Field Detail |
Dimension screenSize
Constructor Detail |
public DrawingBox()
public DrawingBox(String title)
Method Detail |
public void clear()
public void clearRect(int x, int y, int width, int height)
public void drawCircle(int x, int y, int radius)
public void drawCircle(Point p, int radius)
public void drawImage(Image img, int x, int y)
This method waits for the image to be fully loaded.
public void drawLine(int x1, int x2, int y1, int y2)
public void drawOval(int x1, int y1, int width, int height)
x
, y
,
width
, and height
arguments.public void drawRect(int x, int y, int width, int height)
x
and x+width
.
y
and y+height
.
public void drawRect(Rectangle r)
public void drawString(String str, int x, int y)
public void fillCircle(int x, int y, int radius)
public void fillCircle(Point p, int radius)
public void fillOval(int x1, int y1, int width, int height)
public void fillRect(int x, int y, int width, int height)
x
and x+width-1
.
y
and y+height-1
.
width
pixels wide by
height
pixels tall.
public void fillRect(Rectangle r)
public Color getColor()
public int getDrawableHeight()
public int getDrawableWidth()
public void paint(Graphics g)
buffer
has a true
public void setColor(Color c)
public void setDrawableSize(int width, int height)
Association Links |
Graphics
object affiliated with this Frame
to Class java.awt.Dimension
to Class java.awt.Image
g
to Class java.awt.Graphics
Graphics
affiliated with the off-screen image
| |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |