public abstract class GraphicsProgram extends Program implements GraphicsProgramInterface, Iterable<GObject>
Program whose principal window is
used for drawing graphics.JApplet.AccessibleJAppletApplet.AccessibleAppletPanel.AccessibleAWTPanelContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyCONFIG_FILE_NAME, invisibleObjectsaccessibleContext, rootPane, rootPaneCheckingEnabledBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Modifier | Constructor and Description |
|---|---|
protected |
GraphicsProgram()
Creates a new graphics program.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Component comp,
double x,
double y)
Adds the component to the canvas and sets its location to the point (
x, y). |
void |
add(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(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(EventListener listener)
Adds the specified listener as a
MouseListener and/or
MouseMotionListener, as appropriate, to the canvas. |
void |
clear()
Removes all graphical objects from this container.
|
void |
clearCanvas()
Removes all graphical objects from this container.
|
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.
|
double |
getCanvasHeight()
Returns the height of the central canvas area.
|
Dimension |
getCanvasSize()
Returns the size of the central canvas area.
|
double |
getCanvasWidth()
Returns the width of the central canvas area.
|
<T extends GObject> |
getElement(int index)
Returns the graphical object at the specified index, numbering from back
to front in the the z dimension.
|
<T extends GObject> |
getElementAt(double... coords)
This version of getElementAt accepts a variable number of coordinate
pairs (in x1, y1, x2, y2, x3, y3, ...
|
<T extends GObject> |
getElementAt(double x,
double y)
Returns the topmost graphical object that contains the point (
x, y), or null if no such object
exists. |
<T extends 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. |
boolean |
hasElementAt(double... coords)
Returns true if a graphical object exists that touches any of the given
(x, y) pixel positions, or false if no such object exists.
|
boolean |
hasElementAt(double x,
double y)
Returns true if a graphical object exists that touches the given
(x, y) pixel position, or false if no such object exists.
|
void |
init()
Specifies the code to be executed as startup time before the
run method is called. |
boolean |
isAntiAliasing()
Sets whether this program's canvas uses anti-aliasing, which is
smoothing and blending of neighboring pixels.
|
protected boolean |
isStarted()
Checks to see whether this program has started, usually by checking to
see whether some pane exists.
|
Iterator<GObject> |
iterator()
Returns an
Iterator that cycles through the elements within
this container in the default direction, which is from back to front. |
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(double x,
double y)
Removes the top-most graphical object at the given (x, y) position from this container.
|
void |
remove(GObject gobj)
Removes a graphical object from this container.
|
void |
remove(GPoint pt)
Removes the top-most graphical object at the given (x, y) position from this container.
|
void |
removeAll()
Removes all graphical objects from this container.
|
void |
removeAll(double... coords)
Removes all graphical objects at the given (x, y) positions from this container.
|
void |
removeAll(double x,
double y)
Removes all graphical objects at the given (x, y) position from this container.
|
void |
removeAll(GPoint pt)
Removes all graphical objects at the given (x, y) position 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 |
setAntiAliasing(boolean antialias)
Sets whether this program's canvas uses anti-aliasing, which is
smoothing and blending of neighboring pixels.
|
void |
setBackground(Color bg)
Sets the background color of the
GCanvas. |
void |
setCanvasHeight(double height)
Sets this program to be exactly the right size so that its graphical canvas will be
the given height in pixels.
|
void |
setCanvasSize(double width,
double height)
Sets this program to be exactly the right size so that its graphical canvas will be
the given size in pixels.
|
void |
setCanvasWidth(double width)
Sets this program to be exactly the right size so that its graphical canvas will be
the given width in pixels.
|
void |
setShowPixelInfo(boolean show)
Sets whether to display information on this canvas about the current pixel where
the mouse pointer is resting in this program's graphical canvas.
|
void |
setSize(double width,
double height)
Sets this program to be exactly the right size so that its graphical canvas will be
the given size in pixels.
|
void |
setSize(int width,
int height)
Sets this program to be exactly the right size so that its graphical canvas will be
the given size in pixels.
|
void |
setWindowSize(double width,
double height)
Sets this program's window to be the given size in pixels.
|
static void |
startGraphicsProgram(GObject gobj,
String[] args)
Creates a
GraphicsProgram containing the specified
GObject and then starts it. |
BufferedImage |
toImage()
Returns an image representation of the current contents of the screen.
|
void |
waitForClick()
Waits for a mouse click in the window before proceeding.
|
actionPerformed, add, addActionListeners, addActionListeners, addActionListenersToButtonsOnly, addAllActionListeners, addExitHook, addImpl, adjustmentValueChanged, alert, alert, animation, center, changedUpdate, checkCompilerFlags, checkKill, checkStartupSettings, componentAdded, componentHidden, componentMoved, componentRemoved, componentResized, componentShown, confirm, contentsChanged, createConsole, createDialogIO, createMenuBar, createParameterTable, createProgramFrame, destroy, error, error, error, exit, fileExists, fileExists, fileExistsInsideJAR, fileExistsInsideJAR, fileExistsOnDisk, fileExistsOnDisk, fileSize, fileSize, focusGained, focusLost, getAnimationDelay, getAppletStub, getArgumentArray, getBoolean, getBoolean, getBoolean, getBorder, getBottomY, getCenterLocation, getCenterX, getCenterY, getCentralRegionSize, getConsole, getDialog, getDouble, getDouble, getDouble, getDouble, getHeight, getInputModel, getInteger, getInteger, getInteger, getInteger, getJFrame, getLayout, getLine, getLine, getMainThread, getMenuBar, getOutputColor, getOutputModel, getParameter, getParameterTable, getPreferredSize, getReader, getReal, getReal, getReal, getReal, getRegionPanel, getRightX, getScreenHeight, getScreenSize, getScreenWidth, getStartupObject, getTitle, getWidth, getWindow, getWriter, getYesOrNo, hasConfiguration, insertUpdate, intervalAdded, intervalRemoved, isAnimated, isApplet, isAppletMode, isExitOnClose, isInitialized, itemStateChanged, keyPressed, keyReleased, keyTyped, killMe, loadConfiguration, loadConfiguration, main, menuAction, menuCanceled, menuDeselected, menuSelected, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, openFile, openFile, openFileFromDisk, openFileFromDisk, openFileFromJAR, openFileFromJAR, pack, pause, pauseTick, popupMenuCanceled, popupMenuWillBecomeInvisible, popupMenuWillBecomeVisible, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, printf, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, prompt, readBoolean, readBoolean, readBoolean, readDouble, readDouble, readDouble, readDouble, readInt, readInt, readInt, readInt, readLine, readLine, remove, remove, removeFromRegion, removeMenuBar, removeUpdate, runHook, saveConfiguration, saveConfiguration, setAnimated, setAnimationDelay, setAppletStub, setBottomY, setCenterLocation, setCenterX, setCenterY, setConsole, setDialog, setExitOnClose, setFramesPerSecond, setHeight, setInputModel, setInvisible, setJFrame, setJMenuBar, setLayout, setLocation, setLocation, setOutputColor, setOutputModel, setParameter, setParameterTable, setPauseScaleFactor, setResizable, setRightX, setShowPixelGrid, setStartupObject, setTitle, setWidth, setX, setY, showErrorMessage, start, start, startAnimation, startHook, startRun, stateChanged, stopAnimation, textValueChanged, validate, valueChanged, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChangedcreateRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, repaint, setContentPane, setGlassPane, setLayeredPane, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updategetAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, stopadd, 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, processContainerEvent, processEvent, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validateTreeaction, 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitexit, getTitle, pause, print, print, printf, println, println, println, setParameterTable, setStartupObject, setTitle, start, startgetBackground, getFont, getHeight, getSize, getWidth, setFont, setSizemouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleasedmouseDragged, mouseMovedforEach, spliteratorprotected GraphicsProgram()
public void add(GObject gobj)
add in interface GCanvasInterfacegobj - The graphical object to addpublic final void add(GObject gobj, double x, double y)
x, y).add in interface GCanvasInterfacegobj - 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)
add in interface GCanvasInterfacegobj - The graphical object to addpt - The new coordinates of the pointpublic final void add(Component comp, double x, double y)
x, y).add in interface GCanvasInterfacecomp - The component to addx - The new x-coordinate for the objecty - The new y-coordinate for the objectpublic final void add(Component comp, GPoint pt)
add in interface GCanvasInterfacecomp - The component to addpt - A GPoint object giving the coordinates of the
pointpublic void addKeyListeners()
KeyListener to the canvas.addKeyListeners in interface GraphicsProgramInterfacepublic void addKeyListeners(KeyListener listener)
KeyListener to the canvas.addKeyListeners in interface GraphicsProgramInterfacelistener - A KeyListener objectpublic void addMouseListeners()
MouseListener and
MouseMotionListener to the canvas.addMouseListeners in interface GraphicsProgramInterfacepublic void addMouseListeners(EventListener listener)
MouseListener and/or
MouseMotionListener, as appropriate, to the canvas.addMouseListeners in interface GraphicsProgramInterfacelistener - A listener object that is either a MouseListener,
a MouseMotionListener, or bothpublic void clear()
clear in interface GCanvasInterfacepublic void clearCanvas()
clearCanvas in interface GraphicsProgramInterfaceprotected 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()
public double getCanvasHeight()
getCanvasHeight in interface GraphicsProgramInterfacepublic Dimension getCanvasSize()
getCanvasSize in interface GraphicsProgramInterfacepublic double getCanvasWidth()
getCanvasWidth in interface GraphicsProgramInterfacepublic int getElementCount()
GCanvas.getElementCount in interface GCanvasInterfaceGCanvaspublic <T extends GObject> T getElement(int index)
getElement in interface GCanvasInterfaceindex - The index of the component to returnpublic <T extends GObject> T getElementAt(double x, double y)
x, y), or null if no such object
exists.getElementAt in interface GCanvasInterfacex - The x-coordinate of the point being testedy - The y-coordinate of the point being testednull if no such object exists.public <T extends GObject> T getElementAt(double... coords)
getElementAt in interface GCanvasInterfacepublic final <T extends GObject> T getElementAt(GPoint pt)
null if no such object exists.getElementAt in interface GCanvasInterfacept - The coordinates being testednull if no such object existspublic GCanvas getGCanvas()
GCanvas object used by this program.getGCanvas in interface GraphicsProgramInterfaceGCanvas object used by the programpublic boolean hasElementAt(double x,
double y)
hasElementAt in interface GCanvasInterfacepublic boolean hasElementAt(double... coords)
hasElementAt in interface GCanvasInterfacepublic 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.init in interface ProgramInterfaceinit in class Programpublic boolean isAntiAliasing()
isAntiAliasing in interface GCanvasInterfaceprotected boolean isStarted()
public 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 in interface GCanvasInterfaceiterator in interface Iterable<GObject>Iterator ranging over the elements of the
container from back to frontpublic 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 in interface GCanvasInterfaceIterator ranging over the elements of the
container in the specified directionpublic void remove(double x,
double y)
remove in interface GCanvasInterfacepublic void remove(GPoint pt)
remove in interface GCanvasInterfacepublic void remove(GObject gobj)
remove in interface GCanvasInterfacegobj - The graphical object to removepublic void removeAll()
Container version of
removeAll, which is replaced by removeAllComponents.removeAll in interface GCanvasInterfaceremoveAll in class Programpublic void removeAll(double x,
double y)
removeAll in interface GCanvasInterfacepublic void removeAll(double... coords)
removeAll in interface GCanvasInterfacepublic void removeAll(GPoint pt)
removeAll in interface GCanvasInterfacepublic void removeAllComponents()
removeAllComponents in interface GraphicsProgramInterfacepublic void repaint()
repaint in interface GCanvasInterfacerepaint in class Programpublic 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 setAntiAliasing(boolean antialias)
setAntiAliasing in interface GCanvasInterfacepublic void setBackground(Color bg)
GCanvas.setBackground in interface GCanvasInterfacesetBackground in class Programbg - The new background colorpublic void setCanvasHeight(double height)
setCanvasHeight in interface GraphicsProgramInterfaceheight - the desired height of the drawing canvas, in pixelspublic void setCanvasSize(double width,
double height)
setCanvasSize in interface GraphicsProgramInterfacewidth - the desired width of the drawing canvas, in pixelsheight - the desired height of the drawing canvas, in pixelspublic void setCanvasWidth(double width)
setCanvasWidth in interface GraphicsProgramInterfacewidth - the desired width of the drawing canvas, in pixelspublic void setSize(double width,
double height)
setSize in interface GraphicsProgramInterfacesetSize in class Programwidth - the desired width of the drawing canvas, in pixelsheight - the desired height of the drawing canvas, in pixelspublic void setShowPixelInfo(boolean show)
setShowPixelInfo in interface GCanvasInterfacesetShowPixelInfo in class Programpublic void setSize(int width,
int height)
public void setWindowSize(double width,
double height)
setWindowSize in interface GraphicsProgramInterfacewidth - the desired width of the window, in pixelsheight - the desired height of the window, in pixelspublic static void startGraphicsProgram(GObject gobj, String[] args) throws Throwable
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
GraphicsProgramargs - The array of argumentsThrowablepublic BufferedImage toImage()
toImage in interface GCanvasInterfacepublic void waitForClick()
waitForClick in interface GraphicsProgramInterface