import javax.swing.*; import java.awt.*; import static java.lang.Math.*; /* */ public class N_gon extends JApplet { @Override public void paint(Graphics g) { super.paint(g); int np = 7; int sc = 100; int i; double theta1, theta2; for(i = 0; i < np; i++) { // 単位 ラジアン theta1 = PI * 2 * i / np; // 360 * i / n度 theta2 = PI * 2 * (i + 1) / np; // 360 * (i + 1) / n度 g.drawLine((int)(sc * (1.1 + cos(theta1))), (int)(sc * (1.1 + sin(theta1))), (int)(sc * (1.1 + cos(theta2))), (int)(sc * (1.1 + sin(theta2)))); } } public static void main(String[] args) { JFrame frame = new JFrame(""); JApplet applet = new N_gon(); applet.setPreferredSize(new Dimension(220, 220)); frame.add(applet); frame.pack(); frame.setVisible(true); applet.init(); applet.start(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }