用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

请选择技术分类

 *如果你找不到更细的分类,可以选择上级分类
当前位置:云代码 - 技术问答 - Java

星怎么画

 悬赏:10|提问者:buktam|浏览:2402
举报|2013-05-23
星怎么画   给我java 语句就行   谢谢

我来回答

所有回答
举报|(4)|(0)2013-05-27
import java.awt.*;
import javax.swing.*;

public class WuJiaoXing extends JPanel {
	public WuJiaoXing() {
		this.setSize(800, 800);
	}

	public void paint(Graphics g) {

		int c1, c2, c3, w, h, r;
		c1 = (int) (255);
		c2 = (int) (0);
		c3 = (int) (0);
		Color c = new Color(c1, c2, c3);// 随机生成颜色的红绿蓝通道值
		g.setColor(c);// 设置画笔颜色
		w = (int) (Math.random() * 1000);
		h = (int) (Math.random() * 800);
		r = (int) (Math.random() * 80);
		wujiaoxing(g, w, h, r, "fill");

	}

	public void wujiaoxing(Graphics g, int x0, int y0, int r, String f) {
		double ch = 72 * Math.PI / 180;// 圆心角的弧度数
		int x1 = x0, x2 = (int) (x0 - Math.sin(ch) * r), x3 = (int) (x0 + Math
				.sin(ch) * r), x4 = (int) (x0 - Math.sin(ch / 2) * r), x5 = (int) (x0 + Math
				.sin(ch / 2) * r);
		int y1 = y0 - r, y2 = (int) (y0 - Math.cos(ch) * r), y3 = y2, y4 = (int) (y0 + Math
				.cos(ch / 2) * r), y5 = y4;

		int bx = (int) (x0 + Math.cos(ch) * Math.tan(ch / 2) * r);
		int by = y2;

		Polygon a = new Polygon();
		Polygon b = new Polygon();

		a.addPoint(x2, y2);
		a.addPoint(x5, y5);
		a.addPoint(bx, by);
		b.addPoint(x1, y1);
		b.addPoint(bx, by);
		b.addPoint(x3, y3);
		b.addPoint(x4, y4);

		if (f.equals("draw")) {
			g.drawPolygon(a);
			g.drawPolygon(b);
		}
		if (f.equals("fill")) {
			g.fillPolygon(a);
			g.fillPolygon(b);
		}

	}

	public static void main(String[] args) {
		new f();
	}
}

class f extends JFrame {
	WuJiaoXing a = new WuJiaoXing();

	public f() {
		this.setSize(800, 800);
		setLocation(100, 100);
		this.add(a);
		this.setVisible(true);
	}

}


举报|(2)|(0)2013-05-29

public class No6_01 extends Applet

{

    // 顶点X,Y的坐标

    int X[]={100,140,40,160,60};

    int Y[]={50,170,100,100,170};


    public void paint(Graphics g)

    {

        g.drawPolygon(X,Y,5);

    }

}

举报|(0)|(0)2013-06-25

一楼正解!

举报|(0)|(0)2013-08-02
你是要形状是五角星的东西吗?就是用星号给排列组成一个五角星的形状?
举报|(0)|(0)2014-01-11
你是要形状是五角星的东西吗?就是用星号给排列组成一个五角星的形状?
举报|(0)|(0)2014-07-05

public class No6_01 extends Applet

{

    // 顶点X,Y的坐标

    int X[]={100,140,40,160,60};

    int Y[]={50,170,100,100,170};


    public void paint(Graphics g)

    {

        g.drawPolygon(X,Y,5);

    }

}

举报|(0)|(0)2014-09-25
百度!
举报|(0)|(0)2014-09-30
一楼正解
举报|(0)|(0)2015-01-14

百度

举报|(0)|(0)2016-05-01
这个我也不会
举报|(0)|(0)2016-05-19
1L正解
举报|(0)|(0)2017-04-18
??
举报|(0)|(0)2017-08-24
6
举报|(0)|(0)2018-11-06
456
举报|(0)|(0)2018-11-28
大声地说
举报|(0)|(0)2019-07-30
111
举报|(0)|(0)2019-11-02
这是在eclipse上做的吗?

相关提问