-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_polygon2.java
35 lines (32 loc) · 1.02 KB
/
example_polygon2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Panel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Polygon p = new Polygon();
for (int i = 0; i < 5; i++) p.addPoint((int) (
100 + 50 * Math.cos(i * 2 * Math.PI / 5)),(int) (
100 + 50 * Math.sin(i * 2 * Math.PI / 5)));
g.drawPolygon(p);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.YELLOW);
frame.setTitle("DrawPoly");
frame.setSize(350, 250);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new Panel());
frame.show();
}
}