class GWindow| Constructor | |
| GWindow(width, height) | Creates a window of the specified size but does not display it on the screen until the client calls setVisible(true). |
| Methods | |
| close() | Deletes the window from the screen. |
| clear() | Clears the contents of the graphics window. |
| setVisible(flag) | Determines whether the window is visible on the screen. |
| isVisible() | Tests whether the window is visible. |
| drawArc(bounds, start, sweep) drawArc(x, y, width, height, start, sweep) | Draws an elliptical arc inscribed in a rectangle. |
| fillArc(bounds, start, sweep) fillArc(x, y, width, height, start, sweep) | Fills a wedge-shaped area of an elliptical arc. |
| drawImage(filename, pt) drawImage(filename, x, y) drawImage(filename, bounds) drawImage(filename, x, y, width, height) | Draws the image from the specified file with its upper left corner at the specified point. |
| drawLine(p0, p1) drawLine(x0, y0, x1, y1) | Draws a line connecting the specified points. |
| drawPolarLine(p0, r, theta) drawPolarLine(x0, y0, r, theta) | Draws a line of length r in the direction theta from the initial point. |
| drawOval(bounds) drawOval(x, y, width, height) | Draws the frame of a oval with the specified bounds. |
| fillOval(bounds) fillOval(x, y, width, height) | Fills the frame of a oval with the specified bounds. |
| drawRect(bounds) drawRect(x, y, width, height) | Draws the frame of a rectangle with the specified bounds. |
| fillRect(bounds) fillRect(x, y, width, height) | Fills the frame of a rectangle with the specified bounds. |
| drawPolygon(polygon) drawPolygon(polygon, pt) drawPolygon(polygon, x, y) | Draws the outline of the specified polygon. |
| fillPolygon(polygon) fillPolygon(polygon, pt) fillPolygon(polygon, x, y) | Fills the frame of the specified polygon. |
| drawString(str, pt) drawString(str, x, y) | Draws the string str so that its origin appears at the specified point. |
| getStringWidth(str) | Returns the width of the string str when displayed in the current font. |
| setFont(font) | Sets a new font. |
| getFont() | Returns the current font. |
| setColor(color) | Sets the color used for drawing. |
| getColor() | Returns the current color as a string in the form "#rrggbb". |
| saveGraphicsState() | Saves the state of the graphics context. |
| restoreGraphicsState() | Restores the graphics state from the most recent call to saveGraphicsState(). |
| getWindowWidth() | Returns the width of the graphics window in pixels. |
| getWindowHeight() | Returns the height of the graphics window in pixels. |
| repaint() | Schedule a repaint on this window. |
| setWindowTitle(title) | Sets the title of the graphics window. |
| getWindowTitle() | Returns the title of the graphics window. |
| setPainter(painter) | Sets a painter for this window, which is called each time the screen is refreshed after painting the offscreen memory. |
| Functions | |
| getFullScreenWidth() | Returns the width of the entire display screen. |
| getFullScreenHeight() | Returns the height of the entire display screen. |
| getGraphicsWindow() | Returns a reference to the graphics window created by initGraphics. |
| convertColorToRGB(colorName) | Converts a color name into an integer that encodes the red, green, and blue components of the color. |
| convertRGBToColor(rgb) | Converts an rgb value into a color name in the form "#rrggbb". |
GWindow(double width, double height);
setVisible(true).
Usage:
GWindow gw(width, height);
void close();
Usage:
gw.close();
void clear();
Usage:
gw.clear();
void setVisible(bool flag);
Usage:
gw.setVisible(flag);
bool isVisible();
Usage:
if (gw.isVisible()) . . .
void drawArc(GRectangle bounds, double start, double sweep);
void drawArc(double x, double y, double width, double height,
double start, double sweep);
x, y, width, and height
(or, equivalently, the GRectangle bounds)
specify the coordinates and dimensions of the bounding rectangle.
The start parameter indicates the angle at which the
arc begins and is measured in degrees counterclockwise from the
+x axis. Thus, a start angle of 0 indicates
an arc that begins along the line running eastward from the center,
a start angle of 135 begins along the line running
northwest, and a start angle of -90 begins along
the line running south. The sweep parameter indicates
the extent of the arc and is also measured in degrees counterclockwise.
A sweep angle of 90 defines a quarter circle extending
counterclockwise from the start angle, and a
sweep angle of -180 defines a semicircle extending
clockwise.
Usage:
gw.drawArc(bounds, start, sweep); gw.drawArc(x, y, width, height, start, sweep);
void fillArc(GRectangle bounds, double start, double sweep);
void fillArc(double x, double y, double width, double height,
double start, double sweep);
drawArc.
Usage:
gw.fillArc(bounds, start, sweep); gw.fillArc(x, y, width, height, start, sweep);
void drawImage(string filename, GPoint pt);
void drawImage(string filename, double x, double y);
void drawImage(string filename, GRectangle bounds);
void drawImage(string filename, double x, double y,
double width, double height);
Usage:
gw.drawImage(filename, pt); gw.drawImage(filename, x, y); gw.drawImage(filename, bounds); gw.drawImage(filename, x, y, width, height);
void drawLine(GPoint p0, GPoint p1); void drawLine(double x0, double y0, double x1, double y1);
Usage:
gw.drawLine(p0, p1); gw.drawLine(x0, y0, x1, y1);
GPoint drawPolarLine(GPoint p0, double r, double theta); GPoint drawPolarLine(double x0, double y0, double r, double theta);
r in the direction theta
from the initial point. The angle theta is measured in
degrees counterclockwise from the +x axis. The method returns
the end point of the line.
Usage:
GPoint p1 = gw.drawPolarLine(p0, r, theta); GPoint p1 = gw.drawPolarLine(x0, y0, r, theta);
void drawOval(GRectangle bounds); void drawOval(double x, double y, double width, double height);
Usage:
gw.drawOval(bounds); gw.drawOval(x, y, width, height);
void fillOval(GRectangle bounds); void fillOval(double x, double y, double width, double height);
Usage:
gw.fillOval(bounds); gw.fillOval(x, y, width, height);
void drawRect(GRectangle bounds); void drawRect(double x, double y, double width, double height);
Usage:
gw.drawRect(bounds); gw.drawRect(x, y, width, height);
void fillRect(GRectangle bounds); void fillRect(double x, double y, double width, double height);
Usage:
gw.fillRect(bounds); gw.fillRect(x, y, width, height);
void drawPolygon(Vector<GPoint> polygon); void drawPolygon(Vector<GPoint> polygon, GPoint pt); void drawPolygon(Vector<GPoint> polygon, double x, double y);
pt
or x and y parameters shift the origin
of the polygon to the specified point.
Usage:
gw.drawPolygon(polygon); gw.drawPolygon(polygon, pt); gw.drawPolygon(polygon, x, y);
void fillPolygon(Vector<GPoint> polygon); void fillPolygon(Vector<GPoint> polygon, GPoint pt); void fillPolygon(Vector<GPoint> polygon, double x, double y);
pt
or x and y parameters shift the origin
of the polygon to the specified point.
Usage:
gw.fillPolygon(polygon); gw.fillPolygon(polygon, pt); gw.fillPolygon(polygon, x, y);
void drawString(string str, GPoint pt); void drawString(string str, double x, double y);
str so that its origin appears at
the specified point. The text appears in the current font and color.
Usage:
gw.drawString(str, pt); gw.drawString(str, x, y);
double getStringWidth(string str);
str when displayed in
the current font.
Usage:
double width = gw.getStringWidth(str);
void setFont(string font);
font parameter is a string in the
form family-style-size.
In this string, family is the name of the font family;
style is either missing (indicating a plain font) or one
of the strings Bold, Italic, or
BoldItalic; and size is an integer
indicating the point size. If any of these components is
specified as an asterisk, the existing value is retained.
The font parameter can also be a sequence of
such specifications separated by semicolons, in which the
first available font on the system is used.
Usage:
gw.setFont(font);
string getFont();
Usage:
string font = gw.getFont();
void setColor(string color);
color parameter
is usually one of the predefined color names from Java:
BLACK,
BLUE,
CYAN,
DARK_GRAY,
GRAY,
GREEN,
LIGHT_GRAY,
MAGENTA,
ORANGE,
PINK,
RED,
WHITE, or
YELLOW.
The case of the individual letters in the color name is ignored,
as are spaces and underscores, so that the Java color
DARK_GRAY could be written as "Dark Gray".
The color can also be specified as a string in the form
"#rrggbb" where rr, gg, and
bb are pairs of hexadecimal digits indicating the
red, green, and blue components of the color.
Usage:
gw.setColor(color);
string getColor();
"#rrggbb".
In this string, the values rr, gg,
and bb are two-digit hexadecimal values representing
the red, green, and blue components of the color, respectively.
Usage:
string color = gw.getColor();
void saveGraphicsState();
restoreGraphicsState() to avoid
changing the state set up by the client.
Usage:
gw.saveGraphicsState();
void restoreGraphicsState();
saveGraphicsState().
Usage:
gw.restoreGraphicsState();
double getWindowWidth();
Usage:
double width = gw.getWindowWidth();
double getWindowHeight();
Usage:
double height = gw.getWindowHeight();
void repaint();
Usage:
gw.repaint();
void setWindowTitle(string title);
Usage:
gw.setWindowTitle(title);
string getWindowTitle();
Usage:
string title = gw.getWindowTitle();
void setPainter(void (*painter)(GWindow & gw)); void setPainter(Type & painter);
painter parameter is either a procedure that takes
a GWindow argument or an object that has a
paint method.
Usage:
gw.setPainter(painter);
double getFullScreenWidth();
Usage:
width = getFullScreenWidth();
double getFullScreenHeight();
Usage:
height = getFullScreenHeight();
GWindow & getGraphicsWindow();
initGraphics. Because GWindow objects
cannot be copied, the result of getGraphicsWindow
must be used directly and cannot be assigned to a variable.
Usage:
getGraphicsWindow();
int convertColorToRGB(string colorName);
Usage:
int rgb = convertColorToRGB(colorName);
string convertRGBToColor(int rgb);
rgb value into a color name in the
form "#rrggbb". Each of the rr,
gg, and bb values are two-digit
hexadecimal numbers indicating the intensity of that component.
Usage:
int colorName = convertRGBToColor(rgb);