I need some help with my code for a shape drawing class. This is what i have so farQuote:
import java.awt.*;
public class circle implements shapeInt
{
private int xCordCenterPoint;
private int yCordCenterPoint;
private Color c;
private int radius;
private int xcords[];
private int ycords[];
private int fixerX, fixerY;
private final int NUM = 360;
public circle (int cx, int cy, Color color, int r)
{
xCordCenterPoint = cx;
yCordCenterPoint = cy;
c = color;
radius = r;
}
public void drawCenter (Graphics page, boolean showC)
{
if (showC == true)
{
page.setColor (Color.black);
String text = ("." + xCordCenterPoint + "," + yCordCenterPoint);
page.drawString (text, xCordCenterPoint, yCordCenterPoint);
}
}
public void draw(Graphics page, boolean fillShape)
{
xcords = new int [NUM];
ycords = new int [NUM];
page.setColor(c);
for (int i = 0; i < 360; i += 360 / NUM) {
xcords[i] = (int) (radius * Math.sin(i) + xCordCenterPoint);
ycords[i] = (int) (radius * Math.cos(i) + yCordCenterPoint);
}
if(fillShape == true)
page.fillPolygon(xcords, ycords, NUM);
else
page.drawPolygon(xcords, ycords, NUM);
}
public void resize (int xCoord, int yCoord)
{
fixerX = xCoord - xCordCenterPoint;
fixerY = yCoord - yCordCenterPoint;
radius = Math.abs(xCoord - xCordCenterPoint);
}
public void translate (int dx, int dy)
{
xCordCenterPoint = dx - fixerX;
yCordCenterPoint = dy - fixerY;
}
public boolean contains (int xCoord, int yCoord)
{
Polygon three = new Polygon(xcords, ycords, NUM);
boolean contain = three.contains(xCoord, yCoord);
fixerX = xCoord - xCordCenterPoint;
fixerY = yCoord - yCordCenterPoint;
return contain;
}
}
please note that the circle is just one of my few examples. My the contains method at the bottom. As part of the assignment given i'm not allowed to use the polygon class to draw the polygon. Any idea on what to do. I've been searching the awi ref online but i can't find what i need. I need to do this contains method for a circle rectangle square and oval...if that makes a difference