解决方案 »

  1.   


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Table extends Frame implements ActionListener {
    Button start = new Button("开始");
    int[] xx = new int[100];
    int[] yy = new int[100];
    int[] fs1 = new int[100];
    Font fs = null;
    Image offScreen = null;

    public Table() {
    super("雪花飞");
    setSize(1200, 800);
    //setBackground(Color.black);
    // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    setLayout(new FlowLayout());
    add(start);
    start.addActionListener(this);
    validate();
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    } public void actionPerformed(ActionEvent e) {
    if (e.getSource() == start)
    begin();
    } public void begin() {
    for (int i = 0; i < xx.length; i++) {
    xx[i] = (int) (1200 * Math.random());
    yy[i] = (int) (800 * Math.random());
    fs1[i] = (int) (20 * Math.random() + 12);
    }
    new Thread() {
    public void run() {
    while (true) {

    repaint();
    try {
    Thread.sleep(10);
    } catch (InterruptedException e) {
    System.err.println("Thread interrupted");
    }
    }
    }
    }.start();
    } public void paint(Graphics g) {
    super.paint(g);
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, 1200, 800);
    //Image img = new ImageIcon("11.jpg").getImage();
    //g.drawImage(img, 0, 0, 1200, 800, null);
    for (int i = 0; i < xx.length; i++) {
    Font fs = new Font("宋体", Font.BOLD, fs1[i]);
    g.setColor(Color.white);
    g.setFont(fs);
    g.drawString("*", xx[i], yy[i]);// 画雪花
    }

    for (int i = 0; i < xx.length; i++) {
    if ((yy[i] > 800) || (yy[i] < 0))
    yy[i] = 0;
    yy[i]++;
    }
    } public void update(Graphics g) {
    if(offScreen == null) {
    offScreen = createImage(1200, 800);
    }
    Graphics gOffScreen = offScreen.getGraphics();
    paint(gOffScreen);
    g.drawImage(offScreen, 0, 0, null);
    }

    public static void main(String args[]) {
    new Table();
    }
    }
    你的图片我给注释了
      

  2.   


    我也是新手,如果你不会,可以看下马士兵的坦克图片版的视频,里面就有具体的update函数重写,你要看的话可以下载http://pan.baidu.com/share/link?shareid=379477633&uk=202436276
    原因:
      1.刷新重画频率太快,paint方法还没有完成
      2.逐条显示
    解决办法:将所有东西画在虚拟图片上,一次性显示出来
      

  3.   


    offScreen已经声明过了,先判断是否为空,之后就不用再初始化了