[Java] 画图(闪烁的星星和月亮) →→→→→进入此内容的聊天室

来自 , 2020-05-29, 写在 Java, 查看 100 次.
URL http://www.code666.cn/view/1baff70e
  1. import java.awt.*;
  2.  
  3. public class web // 一个类中只能有一个公有的类
  4. {
  5.         public static void main(String[] args) {
  6.                 Frame w = new Frame();// 建立一个窗体的对象
  7.                 w.setSize(1024, 768);// 设置窗体大小
  8.                 w.setBackground(Color.BLACK);// 设置窗体背景颜色
  9.                 MyPanel mp = new MyPanel();//
  10.                 w.add(mp);
  11.                 w.show();
  12.  
  13.         }
  14. }
  15.  
  16. class MyPanel extends Panel // panel为父类,MyPanel为子类
  17. {
  18.         public void paint(Graphics g) {// paint 叫做方法,Graphics是类,g是对象
  19.                 g.setColor(Color.WHITE); // 设置对象的颜色
  20.                 g.fillOval(30, 40, 200, 200);
  21.  
  22.                 for (int i = 0; i < 300; i++) {
  23.                        
  24.                         g.drawString("*", (int) (Math.random() * 1024), (int) (Math.random() * 768));
  25.                         int c1, c2, c3;
  26.                         c1 = (int) (Math.random() * 255);
  27.                         c2 = (int) (Math.random() * 255);
  28.                         c3 = (int) (Math.random() * 255);
  29.  
  30.                         Color c = new Color(c1, c2, c3);
  31.                         g.setColor(c);
  32.                 }
  33.                 g.setColor(Color.BLACK);
  34.                 g.fillOval(50, 40, 200, 200);
  35.         }
  36. }
  37.  

回复 "画图(闪烁的星星和月亮)"

这儿你可以回复上面这条便签

captcha