Class Triangle

public class Triangle
implements Shape

A Triangle class.

Version:
$Id: Triangle.java,v 1.2 2001/04/04 03:25:12 administrator Exp $
Author:
Ben Dugan

Constructor Detail

Triangle

public Triangle()
Create a new triangle of default size. By default, it is filled with the color blue.

Triangle

public Triangle(int x1,
                int y1,
                int x2,
                int y2,
                int x3,
                int y3)
Create a new triangle between these three vertices. By default it is unfilled, but is drawn in the color black.

Triangle

public Triangle(int x1,
                int y1,
                int x2,
                int y2,
                int x3,
                int y3,
                java.awt.Color c,
                boolean fill)
Create a new triangle between these three vertices.
Parameters:
c - a color for the triangle
fill - should the triangle be filled with the color?
Method Detail

toString

public java.lang.String toString()
Description copied from class: ShapeImpl
Answer the printed representation of this shape.
Overrides:
toString in class PolyShape

getBoundingBox

public Rectangle getBoundingBox()
Answer the Rectangle which specifies the bounding box
Overrides:
getBoundingBox in class ShapeImpl

addPoint

public void addPoint(int x,
                     int y)
Add a point to the polygon.

paint

public void paint(java.awt.Graphics g)
Paint the polygon onto the given graphics context.
Overrides:
paint in class ShapeImpl

move

public void move(int dx,
                 int dy)
Translate all the points of the polygon by the given amount.
Overrides:
move in class ShapeImpl
Following copied from interface: Shape
Parameters:
deltaX - offset in the X direction.
deltaY - offset in the Y direction.

setPosition

public void setPosition(int x,
                        int y)

rotate

public void rotate(double degrees)
This method rotates the polygon the given number of degrees about "center" which is computed as the average of all of its points.

main

public static void main(java.lang.String[] args)

setWindow

public void setWindow(GWindow gw)
Attach the shape to the given window.
Specified by:
setWindow in interface Shape

intersects

public boolean intersects(Shape s)
Does this shape intersect the other shape?
Specified by:
intersects in interface Shape

getColor

public java.awt.Color getColor()
Answer the color of this shape.
Specified by:
getColor in interface Shape

setColor

public void setColor(java.awt.Color c)
Set the color of this shape.
Specified by:
setColor in interface Shape