通过继承 JPanel 类和实现 Runnable 类,重写 paint(Graphics g) 和 run() 方法
来完成动态功能的:
class DrawPanel extends JPanel implements Runnable{ public void paint(Graphics g) { super.paint(g); //ToDo } public void run(){ while(true){ this.repaint(); } } }
Container ct = this.getContentPane(); DrawPanel dp = new DrawPanel(); ct.add(dp); Thread t = new Thread(dp); t.start();