Class GWindow
- public class GWindow
The GWindow class defines a simple graphics window. The default
size is 400 by 400 pixels. A "pixel" is one "dot" on the screen.
It is the smallest unit that can be displayed on a window. The
coordinate system is x and y, where x and y are offsets from the
upper left corner of the window. (Note the Y coordinate grows
positively in the downward direction -- which is different from the
traditional Cartesian coordinate system.)
The GWindow supports two modes of displaying objects. In the
first, a GWindow maintains a collection of Shape objects. Shape
objects may be added or removed from the GWindow's container. When
the GWindow paints itself, it paints each of its shape objects, in
the order in which they are added.
In the second, (via 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 often useful for animations.
Shapes obscure other shapes, depending upon the order of their
addition (and their position).
- Version:
- $Id: GWindow.java,v 1.13 2001/05/18 02:52:46 administrator Exp $
- Author:
- Ben Dugan
- See Also:
- Serialized Form
GWindow
public GWindow()
- Create a new window, with default name and size.
GWindow
public GWindow(java.lang.String name)
- Create a new window of the default size.
- Parameters:
name
- the title of the window
GWindow
public GWindow(java.lang.String name,
int width,
int height)
- Create a new window of the given dimensions.
- Parameters:
name
- the title of the windowwidth
- the width of the window, in pixelsheight
- the height of the window, in pixels
version
public double version()
- Answer the version number.
paint
public void paint(java.awt.Graphics g)
- Do a paint operation. Clients will almost never call this
method. It is called by repaint(), or by update() by the
window management system.
- Overrides:
paint
in class java.awt.Container
- Parameters:
g
- a graphics context.
update
public void update(java.awt.Graphics g)
- When we update the window, we just do a paint(g).
- Overrides:
update
in class java.awt.Container
erase
public void erase()
- Discards all of the shape objects and clears the screen.
add
public boolean add(Shape s)
- Add the given shape and paint it onto the screen.
- Parameters:
s
- a shape object (Rectangle, etc)- Returns:
- true if the shape was actually added (a shape is only
added if it hasn't already been added)
display
public void display(Shape s)
- Simply adds this shape to the to-be-displayed queue.
remove
public boolean remove(Shape s)
- Remove the given shape and repaint the screen.
- Parameters:
s
- a shape object (Rectangle, etc)- Returns:
- true if the shape was actually removed, false if not
translate
public void translate(int x,
int y)
- Translate the position of every object by the given deltas,
and repaint the screen.
- Parameters:
x
- the deltaXy
- the deltaY
readInt
public int readInt(java.lang.String prompt)
- Use a dialog box to prompt the user for an integer. If the
user doesn't provide us with an integer, they will be reprompted
until they do.
readDouble
public double readDouble(java.lang.String prompt)
- Use a dialog box to prompt the user for a double. If the
user doesn't provide us with an double, they will be reprompted
until they do.
readChar
public char readChar(java.lang.String prompt)
- Use a dialog box to prompt the user for a character. If the
user doesn't provide us with an character, they will be reprompted
until they do.
readString
public java.lang.String readString(java.lang.String prompt)
- Use a dialog box to prompt the user for a String. Essentially
the entire line that the user types is returned.
print
public void print(java.lang.String msg)
picture
public static void picture()
- Draws a poor approximation of Russian constructivist art :)
showColorTable
public static void showColorTable()
- Opens a color picker application. Click on the color in the
window and the console will show the color you have chosen.
main
public static void main(java.lang.String[] args)