   [java] update()
  1 question this time.When exactly does the update() in the compontent class get used and can u call it inside a program.ok ok so it was 2 questions 
quote:updatepublic void update(Graphics g)    Updates this component.    The AWT calls the update method in response to a call to repaintupdate or paint. You can assume that the background is not cleared.    The updatemethod of Component does the following:  * Clears this component by filling it with the background color.  * Sets the color of the graphics context to be the foreground color of this component.  * Calls this component''s paint method to completely redraw this component.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.    Parameters:   g - the specified context to use for updating.    Since:   JDK1.0    See Also:   paint(java.awt.Graphics), repaint()http://java.sun.com/j2se/1.3/docs/api/java/awt/Component.html#update(java.awt.Graphics)Javadocs are our friends Generally no, you don''t use this method (although you can). If you want to refresh a component usually calling repaint() is what you want, which does...quote:repaintpublic void repaint()    Repaints this component.    This method causes a call to this component''s update method as soon as possible.    Since:   JDK1.0    See Also:   update(java.awt.Graphics)So calling update() yourself is sort of like skipping a step. I think, if it were possible, update() wouldn''t be public. It''s public interface but generally only if you''re working with components at a lower level. ;  ok i understand what ur saying except how can the update method receive a Graphics object as a parameter if Graphics is an abstract class???  ;  That's the good thing about OO-Design: You have an abstract class that provides some (abstract) methods. By subclassing this abstract class, you can create a variety ob objects that all share a common type: They are of the type ob the abstract class.Example: abstract public class Shape {  abstract public float getArea();}public class Square extends Shape {  // Constructor and other methods here.  public float getArea() { return width * height; }}public class Circle extends Shape {  // Constructors and other methods here.  public float getArea() { return radius * radius * pi; }}public class Main {  public static float calcAreas(Shape [] shapes) {    float area = 0.0;    for (int i = 0; i < shapes.length; i++) { area += shapes[i].getArea();    }    return area;  }  public static void main(String [] args) {    Square mysquare = new Square(1.0, 3.0);    Circle mycircle = new Circle(2.0);    Shape [] shapes = new Shape[2];    shapes[0] = mysquare;    shapes[1] = mycircle;    System.out.println("Total area == " + calcAreas(shapes));  }}Hope that answers your question...Beren   [edited by - Beren77 on July 31, 2003 3:54:23 PM] [edited by - Beren77 on July 31, 2003 3:55:20 PM];  ohhhhhhhhhhh! thx alot. I will able to use that in my programs. A graphics object can be an object of any of it''s subclasses!!!:>) 