public class GWindow
extends java.lang.Object
The GWindow supports two modes of displaying objects. In the first, using the add() and remove() operations, a GWindow maintains a collection of Shape objects. When the GWindow paints itself, it paints each of its shape objects, in the order in which they are added. Shapes obscure other shapes, depending upon the order of their addition (and their position); a shape added later overpaints shapes added earlier.
In the second, using the display() method, the GWindow keeps a list of objects to be displayed. The next time the window repaints itself, all objects in the list are displayed, and then discarded. This mode is used in the (old) simulation framework.
Constructor and Description |
---|
GWindow()
Create a new window, with default name and size.
|
GWindow(AppletGWindow appletGWindow)
Create a new window interface to use for an applet
|
GWindow(int width,
int height)
Create a new window of the given dimensions.
|
GWindow(java.lang.String name)
Create a new window of the default size.
|
GWindow(java.lang.String name,
int width,
int height)
Create a new window of the given name and dimensions.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Shape s)
Add the given shape and paint it onto the screen.
|
void |
addEventHandler(GWindowEventHandler handler)
Add the given event handler.
|
void |
display(Shape s)
Simply adds this shape to the to-be-displayed queue.
|
void |
dispose()
Close the window.
|
void |
doRepaint()
Update the screen, if updates aren't suspended.
|
void |
erase()
Discards all of the shape objects and clears the screen.
|
GWindowEventHandler |
getEventHandler()
Answer the current event handler.
|
java.awt.Image |
getImage(java.lang.String imageName)
Deprecated.
|
java.awt.Image |
getImage(java.net.URL imageURL)
Deprecated.
|
java.awt.Image |
getImageFromFilename(java.lang.String imageName)
Create and return a new Image, given the filename of the image.
|
java.awt.Image |
getImageFromURL(java.lang.String imageURL)
Create and return a new Image, given the URL of the image.
|
int |
getWindowHeight()
Return the height of the drawing area of the window (ignoring
title bar, borders, etc.)
|
int |
getWindowWidth()
Return the width of the drawing area of the window (ignoring
title bar, borders, etc.)
|
Shape |
intersects(Shape aShape)
Return the shape that the argument shape intersects with, or null if none.
|
static void |
main(java.lang.String[] args) |
void |
moveAllBy(int deltaX,
int deltaY)
Translate the position of every object by the given deltas,
and repaint the screen.
|
void |
print(java.lang.String msg)
Display a dialog message in a pop-up window.
|
boolean |
remove(Shape s)
Remove the given shape and repaint the screen.
|
void |
resumeRepaints()
Resume repaints.
|
void |
setExitOnClose()
If this is called, the application will exit when a GWindow is
closed.
|
static void |
showColorTable()
Opens a color picker application.
|
void |
startTimerEvents(int intervalInMSecs)
Start delivering timer events to the GWindow.
|
void |
stopTimerEvents()
Stop delivering timer events to the GWindow.
|
void |
suspendRepaints()
Suspend repaints.
|
java.lang.String |
toString() |
double |
version()
Answer the version number.
|
public GWindow()
public GWindow(java.lang.String name)
name
- the title of the windowpublic GWindow(int width, int height)
width
- the initial width of the window, in pixelsheight
- the initial height of the window, in pixelspublic GWindow(java.lang.String name, int width, int height)
name
- the title of the windowwidth
- the initial width of the window, in pixelsheight
- the initial height of the window, in pixelspublic GWindow(AppletGWindow appletGWindow)
appletGWindow
- the AppletGWindow objectpublic void doRepaint()
public void suspendRepaints()
public void resumeRepaints()
public int getWindowWidth()
public int getWindowHeight()
public boolean add(Shape s)
s
- a shape object (Rectangle, etc)public void display(Shape s)
public boolean remove(Shape s)
s
- a shape object (Rectangle, etc)public void erase()
public void moveAllBy(int deltaX, int deltaY)
x
- the deltaXy
- the deltaYpublic Shape intersects(Shape aShape)
aShape
- the shape to test intersection againstpublic void addEventHandler(GWindowEventHandler handler)
public GWindowEventHandler getEventHandler()
public void setExitOnClose()
public void dispose()
public void startTimerEvents(int intervalInMSecs)
public void stopTimerEvents()
public void print(java.lang.String msg)
msg
- the message to displaypublic java.awt.Image getImageFromFilename(java.lang.String imageName)
imageName
- the filename containing the imagepublic java.awt.Image getImageFromURL(java.lang.String imageURL)
imageURL
- the URL containing the imagepublic java.awt.Image getImage(java.lang.String imageName)
imageName
- the filename containing the imagepublic java.awt.Image getImage(java.net.URL imageURL)
imageURL
- the URL containing the imagepublic java.lang.String toString()
toString
in class java.lang.Object
public double version()
public static void showColorTable()
public static void main(java.lang.String[] args)