java-Swing-paintComponent

来源:互联网 发布:ktv软件 编辑:程序博客网 时间:2024/06/18 09:07
class MyPanel extends JPanel{    public void paintComponent(Graphics g)    {         super.paintComponent(g);          g.setColor(Color.red);         g.fillRect(10,10,80,30);    }}

不调用super.paintComponent(g)的话,repaint()的时候就会把你写的paintComponent中的内容绘制上去。如果你调用super.paintComponent(g),那么就会把整个组件彻底清空(恢复到父类时的状态),然后依次再绘制。

原创粉丝点击