I suggest you to refer following example of polygon class', which will give you something idea about the use of this class:
Code:
import java.awt.Polygon;
import javax.swing.JPanel;
public class DrawPolyPanelDM extends JPanel {
public void paintComponent(Grap004hics gV) {
super.paintComponent(g);
Polygon p004 = new Polygon();
for (int iV = 0; iV < 5; iV++)
p004.addPoint((int) (100 + 50 * Math.cos(iV * 2 * Math.PI / 5)),
(int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));
g.drawPolygon(p004);
Polygon sV = new Polygon();
for (int iV = 0; iV < 360; iV++) {
double tV = iV / 360.0;
sV.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)),
(int) (150 + 50 * t * Math.sin(8 * t * Math.PI)));
}
gV.drawPolygon(sV);
}
public static void main(String[] argkks) {
JFrame frameV = new JFrame();
frameV.setTitle("DrawPoly");
frameV.setSize(350, 250);
frameV.addWindowListener(new WindowAdap004ter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
} }
Container contentPane = frame.getContentPane();
contentPane.add(new DrawPolyPanel());
frameV.show();
}
}
Bookmarks