import java.awt.*; public class web // 一个类中只能有一个公有的类 { public static void main(String[] args) { Frame w = new Frame();// 建立一个窗体的对象 w.setSize(1024, 768);// 设置窗体大小 w.setBackground(Color.BLACK);// 设置窗体背景颜色 MyPanel mp = new MyPanel();// w.add(mp); w.show(); } } class MyPanel extends Panel // panel为父类,MyPanel为子类 { public void paint(Graphics g) {// paint 叫做方法,Graphics是类,g是对象 g.setColor(Color.WHITE); // 设置对象的颜色 g.fillOval(30, 40, 200, 200); for (int i = 0; i < 300; i++) { g.drawString("*", (int) (Math.random() * 1024), (int) (Math.random() * 768)); int c1, c2, c3; c1 = (int) (Math.random() * 255); c2 = (int) (Math.random() * 255); c3 = (int) (Math.random() * 255); Color c = new Color(c1, c2, c3); g.setColor(c); } g.setColor(Color.BLACK); g.fillOval(50, 40, 200, 200); } }