Question: using Java and blueJ, write a class and methods to draw polygon on to a canvas to display using the below packages, what are import
using Java and blueJ, write a class and methods to draw polygon on to a canvas to display using the below packages, what are import to the class.
Package m
Class OUPolygon
java.lang.Object
mOUPolygon
public class OUPolygon extends Object
A polygon that can be drawn on a canvas and manipulated. An OUPolygon is specified by its points, which are are joined by line segments. The last point is automatically joined back to the first. Three points makes a triangle. An OUPolygon can be created from a file of points, or using ArrayLists. Foreground colours can be specified using java.awt.Color objects or RGB values. There is a delay method that delays all drawing on the canvas, regardless of which OUPolygon object it is invoked on
Methods are provided to perform transformations on OUPolygons. Transformations that require rounding of values are only approximately reversible.
If you want to change the object assigned to an OUPolygon reference, you should first erase the original object from the canvas.
Version:
Feb
Author:
M Module team
Constructor Summary
Constructors
Constructor
Description
OUPolygonString aFilename,Color aColor
Create an OUPolygon based on points in a named file, with a given colour.
OUPolygonArrayList points, Color aColor
Create an OUPolygon from an ArrayList with a given colour.
OUPolygonArrayList xsl ArrayList ysl Color aColor
Create an OUPolygon from two lists of equal length containing integer x coordinates and y coordinates, with a given colour.
Method Summary
All MethodsStatic MethodsInstance MethodsConcrete Methods
Modifier and Type
Method
Description
void
changeColorint r int g int b
Change the colour of the OUPolygon using RGB components.
void
changeColorColor newColor
Change the colour of the OUPolygon using a java.awt.Color object.
void
changeSizedouble dx double dy
Grow or shrink by a specified amount.
boolean
containsPoint p
Return whether this OUPolygon contains a particular point.
static void
delayint ms
Delay the drawing thread for at least the specified millisecond amount.
void
draw
Draw this OUPolygon on the canvas, if it is visible.
void
erase
Erase this OUPolygon from the canvas.
Rectangle
getBounds
Return the bounding box of this shape.
ArrayList
getPolygonPoints
Return all the points in this OUPolygon as an ArrayList.
boolean
intersectsRectangle r
Return whether this OUPolygon intersects with some Rectangle, typically a bounding box of another shape.
void
makeInvisible
Make this OUPolygon invisible.
void
makeVisible
Make this OUPolygon visible.
void
moveHorizontalint dx
Move the OUPolygon horizontally by a specified distance.
void
moveVerticalint dy
Move the OUPolygon vertically by a specified distance.
void
reflectHorizontallyint xconstant
Reflect this OUPolygon with respect to a vertical line x xconstant.
void
reflectVerticallyint yconstant
Reflect this OUPolygon with respect to a horizontal line y yconstant.
void
rotateAboutPoint centre, double angle
Rotate the whole OUPolygon about a centre of rotation by an angle in degrees, anticlockwise.
void
setPolygonPointsArrayList points
Set the points of this OUPolygon.
void
shearPoint origin, double shx double shy
Shear pushes points in the x andor y directions
String
toString
Return a String representation of this OUPolygon's coordinate points.
void
transformPoint origin,AffineTransform at
Apply an AffineTransform, which can scale, shear and translate a shape, with respect to a provided origin.
void
translateint dx int dy
Move the OUPolygon horizontally and vertically by specified amounts.
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Constructor Details
OUPolygon
public OUPolygonString aFilename,
Color aColor
Create an OUPolygon based on points in a named file, with a given colour. If there are no points in the file, there are no points in the OUPolygon. A new OUPolygon is not drawn on the canvas.
Parameters:
aFilename the name of the file to read points from.
aColor a colour to use for this OUPolygon.
OUPolygon
public OUPolygonArrayList points,
Color aColor
Create an OUPolygon from an ArrayList with a given colour.
Parameters:
points An ArrayList of Points to use for this OUPolygon.
aColor a java.awt.Color to use for this OUPolygon.
OUPolygon
public OUPolygonArrayList xsl
ArrayList ysl
Color aColor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
