求绘制五角星的源代码?? 只要是一个静态的五角星就行多谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import javax.swing.*;public class Test extends JPanel { private JFrame frame = null; private int r = 50; // 半径 private int[] x = new int[5]; // 5个X顶点坐标 private int[] y = new int[5]; // 5个Y顶点坐标 public Test() { this.math(); frame = new JFrame("五角星"); frame.getContentPane().add(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setVisible(true); } private void math() { int c = 360 / 5; // 角度 for (int i = 0; i < 5; i++) { x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r); y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r); } } public void paint(Graphics g) { super.paint(g); g.drawLine(x[0], y[0], x[2], y[2]); g.drawLine(x[0], y[0], x[3], y[3]); g.drawLine(x[1], y[1], x[3], y[3]); g.drawLine(x[1], y[1], x[4], y[4]); g.drawLine(x[2], y[2], x[4], y[4]); g.drawLine(x[2], y[2], x[0], y[0]); } public static void main(String[] args) { new Test(); }} 谁能不能解释一下这两句的意思呀??x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r); 查一下数学书中的正弦、余弦就明白那两句话了。import java.awt.*;import javax.swing.*;public class Test extends JPanel { private JFrame frame = null; private int r = 50; // 外顶点外接圆半径 private int[] x = new int[5]; // 5个X外顶点坐标 private int[] y = new int[5]; // 5个Y外顶点坐标 private int[] x_ = new int[5]; // 5个X内顶点坐标 private int[] y_ = new int[5]; // 5个Y内顶点坐标 public Test() { this.math(); frame = new JFrame("五角星"); frame.getContentPane().add(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setVisible(true); } private void math() { int c = 360 / 5; // 角度 for (int i = 0; i < 5; i++) { x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r); y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r); } int r_ = (int) (r * Math.sin(18 * Math.PI / 180) / Math.sin(126 * Math.PI / 180)); // 内顶点外接圆半径 for (int i = 0; i < 5; i++) { x_[i] = (int) (Math.cos((i * c + 18) * Math.PI / 30 - Math.PI / 2) * (r_) + r); y_[i] = (int) (Math.sin((i * c + 18) * Math.PI / 30 - Math.PI / 2) * (r_) + r); } } public void paint(Graphics g) { super.paint(g); // 填充 int [] x1 = {x[0], x[2], x_[2]}; int [] y1 = {y[0], y[2], y_[2]}; int [] x2 = {x[1], x[3], x_[3]}; int [] y2 = {y[1], y[3], y_[3]}; int [] x3 = {x[2], x[4], x_[4]}; int [] y3 = {y[2], y[4], y_[4]}; g.fillPolygon(x1, y1, 3); g.fillPolygon(x2, y2, 3); g.fillPolygon(x3, y3, 3); // 描边 g.setColor(new Color(255, 0, 0)); g.drawLine(x[0], y[0], x[2], y[2]); g.drawLine(x[0], y[0], x[3], y[3]); g.drawLine(x[1], y[1], x[3], y[3]); g.drawLine(x[1], y[1], x[4], y[4]); g.drawLine(x[2], y[2], x[4], y[4]); g.drawLine(x[2], y[2], x[0], y[0]); } public static void main(String[] args) { new Test(); }} java 构造函数什么时候被调用执行 大家说说我应该参加J2EE培训吗 值的传递 jni传递二维数组的问题 MySQL的JDBC驱动问题,各位大虾帮帮忙 updatestring 如何应用代码来实现数据的导入和导出? 关于Scanner解析文本的问题 连接网页问题? 关于processEvent 与processActionEvent两个事件,在线等候 求高手解决一个困扰很久的问题 要用Eclipse写像DataSource、DataSet这样类?
import javax.swing.*;public class Test extends JPanel { private JFrame frame = null; private int r = 50; // 半径 private int[] x = new int[5]; // 5个X顶点坐标 private int[] y = new int[5]; // 5个Y顶点坐标 public Test() {
this.math();
frame = new JFrame("五角星");
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
} private void math() {
int c = 360 / 5; // 角度
for (int i = 0; i < 5; i++) {
x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
}
} public void paint(Graphics g) {
super.paint(g);
g.drawLine(x[0], y[0], x[2], y[2]);
g.drawLine(x[0], y[0], x[3], y[3]);
g.drawLine(x[1], y[1], x[3], y[3]);
g.drawLine(x[1], y[1], x[4], y[4]);
g.drawLine(x[2], y[2], x[4], y[4]);
g.drawLine(x[2], y[2], x[0], y[0]);
} public static void main(String[] args) {
new Test();
}
}
y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
import java.awt.*;
import javax.swing.*;public class Test extends JPanel { private JFrame frame = null; private int r = 50; // 外顶点外接圆半径 private int[] x = new int[5]; // 5个X外顶点坐标 private int[] y = new int[5]; // 5个Y外顶点坐标 private int[] x_ = new int[5]; // 5个X内顶点坐标 private int[] y_ = new int[5]; // 5个Y内顶点坐标 public Test() {
this.math();
frame = new JFrame("五角星");
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
} private void math() {
int c = 360 / 5; // 角度
for (int i = 0; i < 5; i++) {
x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
}
int r_ = (int) (r * Math.sin(18 * Math.PI / 180) / Math.sin(126 * Math.PI / 180)); // 内顶点外接圆半径
for (int i = 0; i < 5; i++) {
x_[i] = (int) (Math.cos((i * c + 18) * Math.PI / 30 - Math.PI / 2) * (r_) + r);
y_[i] = (int) (Math.sin((i * c + 18) * Math.PI / 30 - Math.PI / 2) * (r_) + r);
}
} public void paint(Graphics g) {
super.paint(g);
// 填充
int [] x1 = {x[0], x[2], x_[2]};
int [] y1 = {y[0], y[2], y_[2]};
int [] x2 = {x[1], x[3], x_[3]};
int [] y2 = {y[1], y[3], y_[3]};
int [] x3 = {x[2], x[4], x_[4]};
int [] y3 = {y[2], y[4], y_[4]};
g.fillPolygon(x1, y1, 3);
g.fillPolygon(x2, y2, 3);
g.fillPolygon(x3, y3, 3);
// 描边
g.setColor(new Color(255, 0, 0));
g.drawLine(x[0], y[0], x[2], y[2]);
g.drawLine(x[0], y[0], x[3], y[3]);
g.drawLine(x[1], y[1], x[3], y[3]);
g.drawLine(x[1], y[1], x[4], y[4]);
g.drawLine(x[2], y[2], x[4], y[4]);
g.drawLine(x[2], y[2], x[0], y[0]); } public static void main(String[] args) {
new Test();
}
}