manova168
May 6th, 2003, 12:30 AM
Could somebody please explain what are the differences among these three graphical methods? I am getting really confused by them.
- paint(Graphics g)
- repaint(Graphics g)
- update(Graphics g)
When do I need them? Where do I use them? How do I use them? What differences do I have to concern with when applying them in an application and in an applet?
CreoN
May 6th, 2003, 02:21 AM
I'm not sure about update(), but the repaint() method you usually use when you want to run the paint()-method, which means redraw the component.
And also, repaint() doesn't want a Graphics object as parameter.
And according to the API:
"
Updates this component.
If this component is not a lightweight component, the AWT calls the update method in response to a call to repaint. You can assume that the background is not cleared.
The updatemethod of Component calls this component's paint method to redraw this component. This method is commonly overridden by subclasses which need to do additional work in response to a call to repaint. Subclasses of Component that override this method should either call super.update(g), or call paint directly.
The origin of the graphics context, its (0, 0) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.
"
the update() method seems to do more or less that work too. Anyone more certain about this?
You could check out Suns article about painting: http://java.sun.com/products/jfc/tsc/articles/painting/index.html