Hey im doing my midterm for CS1400, and ran into a snag.
First of all some background. We are supposed to use shapes to draw a picture.
Our example was a bat man sign, which was created by using ovals.
So I decided to try and create the transformer autobot sign, since it was just released, etc.
I started to do ok. I used several Rectangles and Oval, and Arcs, but when I tried to use a polygon, the object doesn't show up on my screen.
Here is my code for the 'Poly' class:
/**
* Draws a Poly and fills it
*
* @author Brett Unzaga
* @version 07-14-07
*/
import javax.swing.*;
import java.awt.*;
public class Poly extends JComponent
{
int[] XPoints;
int[] YPoints;
int NPoints;
public Poly(int[] xPoints, int[] yPoints, int nPoints)
{
super();
setBackground(Color.blue);
NPoints=nPoints;
XPoints = new int[NPoints];
for (int i=0;i<NPoints;i++)
{
XPoints=xPoints;
}
YPoints=new int[NPoints];
for (int i=0;i<NPoints;i++)
{
YPoints=yPoints;
}
}
public void paint(Graphics g)
{
g.setColor(getBackground());
g.fillPolygon(XPoints, YPoints, NPoints);
paintChildren(g);
}
}
And here is the code Im trying to call this method with. Please let me know if I have any redundant or un necessary code:
private Poly poly;
int[] X={200,100,100};
int[] Y={50,300,100};
poly = new Poly(X,Y,3);
poly.setBackground(Color.BLACK);
mainWin.add(poly,0);
I'd like to be able to just do something like:
poly=new Poly([200,100,100],[50,300,100],3);
but it tells me it is an 'Illegal start of expression'
Thanks for any help!