java五角星代码 java用星号输入五角星

一个五角星的JAVA代码是什么?拜托各位了 3Qimport java.applet.*; import java.awt.*; public class Wjx extends java.applet.Applet implements Runnable{ Thread PaintThread; public void init() {} public void start(){ PaintThread=new Thread(this); PaintThread.start(); } public void stop(){ PaintThread=null; } public void paint(Graphics g){ //变量定义及初始化 int x[], y[], ox, oy, i, j, R, r, w, h; double a, inca, cura; Color c; int cr, cg, cb;inca=2 * Math.PI / 5; x=new int[10]; y=new int[10]; w=getSize().width; h=getSize().height;//五角星 for (i=0; i50; i++){//随机五角星特征 ox=(int)(Math.random() * w); oy=(int)(Math.random() * w); R=(int)(Math.random() * 50); r=(int)(R / 2); a=(int)(Math.random() * 2 * Math.PI / 5);//计算顶点数据 for(j=0; j10; j+=2){ cura=a + inca * (j / 2); x[j]=ox + (int)(R * Math.sin(cura)); y[j]=oy + (int)(R * Math.cos(cura));cura=cura + inca / 2; x[j+1]=ox + (int)(r * Math.sin(cura)); y[j+1]=oy + (int)(r * Math.cos(cura)); }cr=(int)(Math.random() * 255); cg=(int)(Math.random() * 255); cb=(int)(Math.random() * 255); c=new Color(cr, cg, cb);//画出五角星 g.setColor(c); g.fillPolygon(x, y, 10); } } public void run() { while(PaintThread!=null){ repaint(); try{ Thread.sleep(125); } catch(InterruptedException E){ } } } }
java中五角星怎么用代码去打=========以下代码抄的
import java.awt.*;
import javax.swing.*;
public class WuJiaoXing extends JPanel {
private static final long serialVersionUID = 1L;
private JFrame frame = null;
private int r = 150; // 外顶点外接圆半径
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 WuJiaoXing() {
this.math();
frame = new JFrame("五角星");
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLocation(200, 200);
frame.setVisible(true);
}
private void math() {
int c = 360 / 5; // 角度
for (int i = 0; i5; 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; i5; 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);
g.setColor(Color.YELLOW);
// g.setBackground(Color.RED);
// 填充
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(Color.BLACK);
// 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 WuJiaoXing();
}
}
第二种 , 用控制台
class Pentagram {
private final char FILL_CHAR;// 填充字符
private final char SPACE_CHAR;// 空档字符
private final int R;// 五角星的外接圆半径
private final float ROTATION;// 五角星逆时针旋转角度
private final int X;// 用于生成画图数组
private final int Y;// 用于生成画图数组

推荐阅读