hi there i'm having a trouble while i'm trying to draw a polygon. first of all, when i try to draw a polygon with using addPoint(int x, int y)
method and giving coordinates one by one there is no problem, polygon could be drawed perfectly. however, if i give the coordinates as an array (an integer array for x coordinates and y coordinates) compiler gives error. this is the working code as you can see,
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Polygon poly = new Polygon();
poly.addPoint(150, 150);
poly.addPoint(250, 100);
poly.addPoint(325, 125);
poly.addPoint(375, 225);
poly.addPoint(450, 250);
poly.addPoint(275, 375);
poly.addPoint(100, 300);
g2.drawPolygon(poly);
}
but if i use the xpoints
and ypoints
array (which are defined in Graphics class for polygon) it doesnt work properly.
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Polygon poly = new Polygon();
poly.xpoints[0]=150;
poly.xpoints[1]=250;
poly.xpoints[2]=325;
poly.xpoints[3]=375;
poly.xpoints[4]=450;
poly.xpoints[5]=275;
poly.xpoints[6]=100;
poly.ypoints[0]=150;
poly.ypoints[1]=100;
poly.ypoints[2]=125;
poly.ypoints[3]=225;
poly.ypoints[4]=250;
poly.ypoints[5]=375;
poly.ypoints[6]=300;
g2.drawPolygon(poly.xpoints, poly.ypoints, 7);
}
i will appreciate if you can help and thanks anyway.