java.awt.Componentpublic void paint(Graphics g)
Paints this component. 
This method is called when the contents of the component should be painted in response to the component first being shown or damage needing repair. The clip rectangle in the Graphics parameter will be set to the area which needs to be painted. Subclasses of Component that override this method need not call super.paint(g). For performance reasons, Components with zero width or height aren't considered to need painting when they are first shown, and also aren't considered to need repair. 
Parameters:
g - the graphics context to use for painting
Since:
JDK1.0 *******************************************************************javax.swing.JComponentprotected void paintComponent(Graphics g)
Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate). 
If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts. 
Parameters:
g - the Graphics object to protect

解决方案 »

  1.   

    javax.swing.JComponentpublic void paint(Graphics g)
    Invoked by Swing to draw components. Applications should not invoke paint directly, but should instead use the repaint method to schedule the component for redrawing. 
    This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent. 
    Overrides:
    paint in class Container
    Parameters:
    g - the Graphics context in which to paint
      

  2.   

    那有关jar和包的问题有谁了解呀