Question: using Java and blueJ, write a class and methods to draw polygon from a file on to a canvas to display using the below packages,

using Java and blueJ, write a class and methods to draw polygon from a file on to a canvas to display using the below packages, what are import to the class.
Package m250
Class OUPolygon
java.lang.Object
m250.OUPolygon
________________________________________
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:
20 Feb 2024
Author:
M250 Module team
Constructor Summary
Constructors
Constructor
Description
OUPolygon(String aFilename,Color aColor)
Create an OUPolygon based on points in a named file, with a given colour.
OUPolygon(ArrayList points, Color aColor)
Create an OUPolygon from an ArrayList with a given colour.
OUPolygon(ArrayList 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
changeColor(int r, int g, int b)
Change the colour of the OUPolygon using RGB components.
void
changeColor(Color newColor)
Change the colour of the OUPolygon using a java.awt.Color object.
void
changeSize(double dx, double dy)
Grow (or shrink) by a specified amount.
boolean
contains(Point p)
Return whether this OUPolygon contains a particular point.
static void
delay(int 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
intersects(Rectangle 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
moveHorizontal(int dx)
Move the OUPolygon horizontally by a specified distance.
void
moveVertical(int dy)
Move the OUPolygon vertically by a specified distance.
void
reflectHorizontally(int xconstant)
Reflect this OUPolygon with respect to a vertical line x = xconstant.
void
reflectVertically(int yconstant)
Reflect this OUPolygon with respect to a horizontal line y = yconstant.
void
rotateAbout(Point centre, double angle)
Rotate the whole OUPolygon about a centre of rotation by an angle in degrees, anticlockwise.
void
setPolygonPoints(ArrayList points)
Set the points of this OUPolygon.
void
shear(Point origin, double shx, double shy)
Shear pushes points in the x and/or y direction(s).
String
toString()
Return a String representation of this OUPolygon's coordinate points.
void
transform(Point origin,AffineTransform at)
Apply an AffineTransform, which can scale, shear and translate a shape, with respect to a provided origin.
void
translate(int 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 OUPolygon(String 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 OUPolygon(ArrayList 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 OUPolygon(ArrayList xsl,
ArrayList ysl,
Color aColor)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!