|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
acm.program.Program
acm.program.GraphicsProgram
public abstract class GraphicsProgram
This class is a standard subclass of Program
whose principal window is used for drawing graphics.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JApplet |
|---|
JApplet.AccessibleJApplet |
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class acm.program.Program |
|---|
CENTER, EAST, NORTH, SOUTH, WEST |
| Fields inherited from class javax.swing.JApplet |
|---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
protected |
GraphicsProgram()
Creates a new graphics program. |
| Method Summary | |
|---|---|
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. |
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. |
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(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(Color bg)
Sets the background color of the GCanvas. |
static void |
startGraphicsProgram(GObject gobj,
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. |
| Methods inherited from class javax.swing.JApplet |
|---|
createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setRootPane, setRootPaneCheckingEnabled, update |
| Methods inherited from class java.applet.Applet |
|---|
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, stop |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected GraphicsProgram()
| Method Detail |
|---|
public final void add(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 object
public final void add(Component comp,
GPoint pt)
comp - The component to addpt - A GPoint object giving the coordinates of the pointpublic void add(GObject gobj)
gobj - The graphical object to add
public 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 object
public final void add(GObject gobj,
GPoint pt)
gobj - The graphical object to addpt - The new coordinates of the pointpublic void addKeyListeners()
KeyListener to the canvas.
public void addKeyListeners(KeyListener listener)
KeyListener to the canvas.
listener - A KeyListener objectpublic void addMouseListeners()
MouseListener and MouseMotionListener
to the canvas.
public void addMouseListeners(EventListener listener)
MouseListener and/or
MouseMotionListener, as appropriate, to the canvas.
listener - A listener object that is either a MouseListener, a
MouseMotionListener, or bothprotected 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()
endHook in class Programpublic GObject getElement(int index)
index - The index of the component to return
public 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 tested
null
if no such object exists.public final GObject getElementAt(GPoint pt)
null if no such object exists.
pt - The coordinates being tested
null
if no such object existspublic int getElementCount()
GCanvas.
GCanvaspublic GCanvas getGCanvas()
GCanvas object used by this program.
GCanvas object used by the programpublic 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 class Programprotected boolean isStarted()
isStarted in class Programpublic 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 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 remove(GObject gobj)
gobj - The graphical object to removepublic void removeAll()
Container version of
removeAll, which is replaced by
removeAllComponents.
removeAll in class Programpublic void removeAllComponents()
public void repaint()
repaint 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.
run in interface Runnablerun in class Programpublic void setBackground(Color bg)
GCanvas.
setBackground in class Programbg - The new background color
public static void startGraphicsProgram(GObject gobj,
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 GraphicsProgramargs - The array of argumentspublic void waitForClick()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||