建立MyStar和MyStarpanel的.java的文件 /** * 满天星的画布 */ public class MyStarPanel extends JPanel implements Runnable { /*1.变量声明区域*/ int[] xx = new int[100]; int[] yy = new int[100]; /*2.构造方法区域 静态代码块*/ public MyStarPanel(){ for (int i =0;i<100;i++){ xx[i]=(int)(Math.random()*900); yy[i]=(int)(Math.random()*700); } } /*3.绘制区域-JPanel*/ @Override public void paint(Graphics g) { super.paint(g); //3.1 设置背景颜色 this.setBackground(Color.BLACK); // 3.5月亮 g.setColor(Color.pink); g.fillOval(100,100,100,100); // 3.6月牙 g.setColor(Color.black); g.fillOval(80,80,100,100); //g是画笔 //设置字体样式 Font ft = new Font("微软雅黑",Font.BOLD,28); g.setFont(ft); //3.3绘制小星星 g.setColor(Color.YELLOW); //3.4绘制满天星 for(int i = 0;i<1