我现在现在一个JPanel上绘图,图形是时时更新的敢问,如何实现呢?
我以下代码不能实现
import java.awt.*;
import javax.swing.*;public class drawonpanel
    extends JPanel {
  public drawonpanel() {
    //super();
    //使部件变得透明
    setOpaque(true); // we don't paint all our bits
    //setLayout(new BorderLayout());
    setBorder(BorderFactory.createLineBorder(Color.black));
    this.setBackground(Color.black);
  }  public Dimension getPreferredSize() {
    Dimension layoutSize = super.getPreferredSize();
    int max = Math.max(layoutSize.width, layoutSize.height);
    return new Dimension(max + 100, max + 100);
  }  protected void paintComponent(Graphics g) {
    //this.setBackground(Color.BLACK);
    int i =10;
    while(true){
     Color c = new Color( (int) (Math.random() * 0xffffff));
      g.setColor(c);
      g.drawString("i am a boy!", 50 + i, 50 + i);
      i += 20;
    }
  }}