目前还是不是很清楚他们的区别,哪位大虾指点迷津下吧:)

解决方案 »

  1.   

    paint()是抽象类java.awt.Component中定义的;而paintComponent()是类java.awt.Container中第一的方法。
    关于这两个类的区别,看它们的api文档描述
      

  2.   

    paint是全部东西都要重画的
    paintComponent只是重画上面的容器
    所以很明显的
    后者速度比前者要快
    一般情况下都是用后者的
    除非对于JFrame,才会用到前者
    LZ可以体会一下哈~
      

  3.   

    对于GUI设计来说,如果你用AWT,paint()是你要用的东西;如果你用Swing,paintComponent()是你要用的东西。
    Painting is much different in Swing than it is in AWT. In AWT we typically override Component’s paint() method to do rendering and the update() method for things like implementing our own double-buffering or filling the background before paint() is called.With Swing, component rendering is much more complex. Though JComponent is a subclass of Component, it uses the update() and paint() methods for different reasons. In fact, the update() method is never invoked at all. There are also five additional stages of painting that normally occur from within the paint() method. ... but it suffices to say here that any JComponent subclass that wants to take control of its own rendering should override the paintComponent() method and not the paint() method. Additionally, it should always begin its paintComponent() method with a call to super.paintComponent().