public abstract class GraphicsProgram extends Program
Program
whose principal window is used for drawing graphics.Modifier and Type | Method and Description |
---|---|
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 this canvas and sets its location
to the point (
x , y ). |
void |
add(GObject gobj,
GPoint pt)
Adds the graphical object to this 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. |
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()
The init method is called at startup time before the run method is
called.
|
java.util.Iterator |
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 |
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()
Contains the code to be executed for each specific program subclass.
|
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, destroy, exit, getConsole, getDialog, getHeight, getInputModel, getLayout, getMenuBar, getOutputModel, getParameter, getPreferredSize, getReader, getRegionPanel, getTitle, getWidth, getWriter, isAppletMode, 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, setConsole, setLayout, setTitle, showErrorMessage, start, start, validate
getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setTransferHandler, update
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getListeners, getMaximumSize, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocusInWindow, reshape, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public void run()
GraphicsProgram
class, you need to
override the definition of run
so that it contains the code
for your application.public void init()
init
method.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 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 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 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 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
Sets
- the background color of the underlying GCanvas
public 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 arguments