graphics
Class Window

java.lang.Object
  |
  +--graphics.Window

public class Window
extends java.lang.Object

A Window that can be drawn onto. Various shapes can be drawn onto this window. Mouse events are also trapped and recorded. The following code shows how a Window might be used

    Window win = new Window();
 
    // Create a circle centred on (50, 100) with a radius of 50.
    Circle c = new Circle(50, 100, 50);
 
    // Now draw the circle on the window
    win.draw(c);
 


Constructor Summary
Window()
          Construct a window of 500 by 400 pixels
Window(int x, int y)
          Construct a window.
 
Method Summary
 void clear(Shape shape)
          Clears a shape.
 void draw(Point p)
          Draw a point using the current foreground colour.
 void draw(Shape shape)
          Draw any of the graphics shapes (for example a Circle) in the current foreground colour.
 void erase(Shape shape)
          Erases a shape.
 void fill(Shape shape)
          Fills a shape with the current foreground colour.
 Color getBackground()
          Get the background colour
 Color getForeground()
          Get the foreground colour
 Point getMouse()
          Get the current mouse position
 Point getMousePress()
          Get the last point where the mouse was pressed.
 boolean isPressed()
          Determine if the mouse is pressed or not.
 void setAntiAliasing(boolean alias)
          Turns anti-aliasing on or off.
 void setBackground(Color c)
          Set the background colour Used by the erase and clear commands.
 void setForeground(Color c)
          Set the foreground colour All draw and fill commands will now use this colour.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Window

public Window(int x,
              int y)
Construct a window.

Parameters:
x - The width of the window in pixels
y - The height of the window in pixels

Window

public Window()
Construct a window of 500 by 400 pixels

Method Detail

draw

public void draw(Shape shape)
Draw any of the graphics shapes (for example a Circle) in the current foreground colour.

Parameters:
shape - The shape to draw

draw

public void draw(Point p)
Draw a point using the current foreground colour.


fill

public void fill(Shape shape)
Fills a shape with the current foreground colour.

Parameters:
shape - Shape to be filled

erase

public void erase(Shape shape)
Erases a shape. In effect, this draws the shape with the current background colour.

Parameters:
shape - The shape to erase.

clear

public void clear(Shape shape)
Clears a shape. In effect, this fills the shape with the current background colour.

Parameters:
shape - The shape to clear.

setForeground

public void setForeground(Color c)
Set the foreground colour All draw and fill commands will now use this colour.

Parameters:
c - The new foreground colour.

getForeground

public Color getForeground()
Get the foreground colour

Returns:
The current foreground colour.

setBackground

public void setBackground(Color c)
Set the background colour Used by the erase and clear commands.

Parameters:
c - The background colour.

getBackground

public Color getBackground()
Get the background colour

Returns:
The current background colour.

isPressed

public boolean isPressed()
Determine if the mouse is pressed or not.

Returns:
true if the mouse is currently pressed, false otherwise.

getMouse

public Point getMouse()
Get the current mouse position

Returns:
Current position of the mouse.

getMousePress

public Point getMousePress()
Get the last point where the mouse was pressed.

Returns:
Last point where the mouse was pressed.

setAntiAliasing

public void setAntiAliasing(boolean alias)
Turns anti-aliasing on or off. Anti-aliasing is an ingenious technique to make drawings look smoother by varying the shades of pixels which do not completely fall in the drawing curve. Pixel based graphics can look blocky (pixelated) because a particular point is either completely on or off. Anti-aliasing makes a pixel appear to be partially on by using a shade of gray rather than black or white.

A disadvantage is that images can take longer to draw.

Look up google for a better explanation.

Parameters:
alias - true if we want anti-aliasing, false otherwise.