public abstract class GraphicsProgram extends Program
Program
whose principal window is
used for drawing graphics.javax.swing.JFrame.AccessibleJFrame
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Modifier | Constructor and Description |
---|---|
protected |
GraphicsProgram()
Creates a new graphics program.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.awt.Component comp,
double x,
double y)
Adds the component to the canvas and sets its location to the point
(
x , y ). |
void |
add(java.awt.Component comp,
GPoint pt)
Adds the component to the canvas and sets its location to the specified
point.
|
void |
add(GObject gobj)
Adds a new graphical object to this container.
|
void |
add(GObject gobj,
double x,
double y)
Adds the graphical object to the canvas and sets its location to the point
(
x , y ). |
void |
add(GObject gobj,
GPoint pt)
Adds the graphical object to the canvas and sets its location to the
specified point.
|
void |
addKeyListeners()
Adds the program as a
KeyListener to the canvas. |
void |
addKeyListeners(java.awt.event.KeyListener listener)
Adds the specified listener as a
KeyListener to the canvas. |
void |
addMouseListeners()
Adds the program as both a
MouseListener and
MouseMotionListener to the canvas. |
void |
addMouseListeners(java.util.EventListener listener)
Adds the specified listener as a
MouseListener and/or
MouseMotionListener , as appropriate, to the canvas. |
protected GCanvas |
createGCanvas()
Creates the
GCanvas used by the GraphicsProgram . |
protected void |
endHook()
Ensures that the window is repainted at the end of the program.
|
GObject |
getElement(int index)
Returns the graphical object at the specified index, numbering from back to
front in the the z dimension.
|
GObject |
getElementAt(double x,
double y)
Returns the topmost graphical object that contains the point (
x ,
y ), or null if no such object exists. |
GObject |
getElementAt(GPoint pt)
Returns the topmost graphical object that contains the specified point, or
null if no such object exists. |
int |
getElementCount()
Returns the number of graphical objects stored in this
GCanvas . |
GCanvas |
getGCanvas()
Returns the
GCanvas object used by this program. |
void |
init()
Specifies the code to be executed as startup time before the
run
method is called. |
protected boolean |
isStarted()
Checks to see whether this program has started, usually by checking to see
whether some pane exists.
|
java.util.Iterator<GObject> |
iterator()
Returns an
Iterator that cycles through the elements within this
container in the default direction, which is from back to front. |
java.util.Iterator<GObject> |
iterator(int direction)
Returns an
Iterator that cycles through the elements within this
container in the specified direction, which must be one of the constants
FRONT_TO_BACK or
BACK_TO_FRONT from
the GContainer
interface. |
void |
remove(GObject gobj)
Removes a graphical object from this container.
|
void |
removeAll()
Removes all graphical objects from this container.
|
void |
removeAllComponents()
Removes all components from this container.
|
void |
repaint()
Signals a need to repaint this window.
|
void |
run()
Specifies the code to be executed as the program runs.
|
void |
setBackground(java.awt.Color bg)
Sets the background color of the
GCanvas . |
static void |
startGraphicsProgram(GObject gobj,
java.lang.String[] args)
Creates a
GraphicsProgram containing the specified
GObject and then starts it. |
void |
waitForClick()
Waits for a mouse click in the window before proceeding.
|
actionPerformed, add, addActionListeners, addActionListeners, addExitHook, addImpl, createConsole, createDialogIO, createMenuBar, createParameterTable, destroy, exit, getArgumentArray, getBorder, getCentralRegionSize, getConsole, getDialog, getInputModel, getLayout, getMainThread, getOutputModel, getParameter, getParameterTable, getProgramMenuBar, getReader, getRegionPanel, getStartupObject, getWriter, keyPressed, keyReleased, keyTyped, main, menuAction, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, pause, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, readBoolean, readBoolean, readBoolean, readDouble, readDouble, readDouble, readDouble, readInt, readInt, readInt, readInt, readLine, readLine, remove, remove, runHook, setConsole, setContentSize, setDialog, setInputModel, setLayout, setOutputModel, setParameter, setParameterTable, setStartupObject, showErrorMessage, start, start, startHook, startRun, validate
createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public void run()
run
method is required for applications that have a thread of control that runs
even in the absence of user actions, such as a program that uses console
interation or that involves animation. GUI-based programs that operate by
setting up an initial configuration and then wait for user events usually do
not specify a run
method and supply a new definition for
init
instead.public void init()
run
method is called. Subclasses can override this method to perform any
initialization code that would ordinarily be included in an applet
init
method. In general, subclasses will override
init
in GUI-based programs where the program simply sets up an
initial state and then waits for events from the user. The run
method is required for applications in which there needs to be some control
thread while the program runs, as in a typical animation.public GCanvas getGCanvas()
GCanvas
object used by this program.GCanvas
object used by the programpublic void add(GObject gobj)
gobj
- The graphical object to addpublic final void add(GObject gobj, double x, double y)
x
, y
).gobj
- The graphical object to addx
- The new x-coordinate for the objecty
- The new y-coordinate for the objectpublic final void add(GObject gobj, GPoint pt)
gobj
- The graphical object to addpt
- The new coordinates of the pointpublic final void add(java.awt.Component comp, double x, double y)
x
, y
).comp
- The component to addx
- The new x-coordinate for the objecty
- The new y-coordinate for the objectpublic final void add(java.awt.Component comp, GPoint pt)
comp
- The component to addpt
- A GPoint
object giving the coordinates of the pointpublic void remove(GObject gobj)
gobj
- The graphical object to removepublic void removeAll()
Container
version of removeAll
, which
is replaced by
removeAllComponents
.public int getElementCount()
GCanvas
.GCanvas
public GObject getElement(int index)
index
- The index of the component to returnpublic GObject getElementAt(double x, double y)
x
,
y
), or null
if no such object exists.x
- The x-coordinate of the point being testedy
- The y-coordinate of the point being testednull
if no such object exists.public final GObject getElementAt(GPoint pt)
null
if no such object exists.pt
- The coordinates being testednull
if no such object existspublic java.util.Iterator<GObject> iterator()
Iterator
that cycles through the elements within this
container in the default direction, which is from back to front. You can also
run the iterator in the opposite direction by using the
iterator
(
direction)
form of this method.
Applets that want to run in browsers, however, should avoid using this
method, because Iterator
is not supported on 1.1 browsers. For
maximum portability, you should rely instead on the
getElementCount
and getElement
methods, which provide the same functionality in a browser-compatible way.
Iterator
ranging over the elements of the container
from back to frontpublic java.util.Iterator<GObject> iterator(int direction)
Iterator
that cycles through the elements within this
container in the specified direction, which must be one of the constants
FRONT_TO_BACK
or
BACK_TO_FRONT
from
the GContainer
interface.
for (Iterator<GObject> i = iterator(direction); i.hasNext(); )
Applets that want to run in browsers, however, should avoid using this
method, because Iterator
is not supported on 1.1 browsers. For
maximum portability, you should rely instead on the
getElementCount
and getElement
methods, which provide the same functionality in a browser-compatible way.
Iterator
ranging over the elements of the container
in the specified directionpublic void addMouseListeners()
MouseListener
and
MouseMotionListener
to the canvas.public void addMouseListeners(java.util.EventListener listener)
MouseListener
and/or
MouseMotionListener
, as appropriate, to the canvas.listener
- A listener object that is either a
MouseListener
, a
MouseMotionListener
, or bothpublic void addKeyListeners()
KeyListener
to the canvas.public void addKeyListeners(java.awt.event.KeyListener listener)
KeyListener
to the canvas.listener
- A KeyListener
objectpublic void waitForClick()
public void repaint()
public void removeAllComponents()
public void setBackground(java.awt.Color bg)
GCanvas
.setBackground
in class Program
bg
- The new background colorpublic static void startGraphicsProgram(GObject gobj, java.lang.String[] args)
GraphicsProgram
containing the specified
GObject
and then starts it. This code is called only by the
start
method in GObject
.gobj
- The object to be inserted into the GraphicsProgram
args
- The array of argumentsprotected GCanvas createGCanvas()
GCanvas
used by the GraphicsProgram
.
Subclasses can override this method to create their own GCanvas
types.GCanvas
to be inserted into the programprotected void endHook()