File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Need help on Graphics and repaint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help on Graphics and repaint" Watch "Need help on Graphics and repaint" New topic

Need help on Graphics and repaint

osama felfel

Joined: Jan 07, 2010
Posts: 2
I don`t know if this is the right place to post my topic but I really need help from you.
I have two questions that I can`t find any answers to them.

In java.awt package there is an graphics class this class is abstract class and within it a lot of abstract methods for example lets take drawOval method all I want to know:
1- when I override paint method of an component like this:
public void paint(Graphics g) { /*some code*/ }
If I write g.drawOval and give the method it`s parameter it`s really draw an oval how this happened when this method is abstract and it has no code within it ??? Is there are some default code in abstract methods or what??? And if this is true whrer to write this code ???
2- when I want to call paint method I have read that I should use repaint(). why? and how repaint call paint if I checked repaint source code & it does not call paint method??? and why I can`t just call paint method ???

I really don`t know if these questions are stupid but if they are or not please answer me cause I can`t do any thing except searching answers .....
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

osama felfel wrote:... I really need help from u.

Please use real words when posting to the forums. Abbreviations such as "u" in place of "you" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

JavaRanch sheriff

[Asking smart questions] [About Bear] [Books by Bear]
osama felfel

Joined: Jan 07, 2010
Posts: 2
I`m really sorry and I will edit my post
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
And people will be more likely to help if they know what the thread is about.
pete stein

Joined: Feb 23, 2007
Posts: 1561
While the paint method says that it receives a Graphics object as a parameter, this method really doesn't receive a simple Graphics object. Instead it must receive an object of a class that is derived from Graphics, one that implements all the abstract methods. It is not necessary to know how the JVM implements the methods, it is not necessary to know the name of this class (and indeed, the class may have no name -- an anonymous class). All that you need to know is that the object is of a class that is descendant from the Graphics class and that obeys all the rules stipulated by the Graphics class method definitions.
I agree. Here's the link:
subject: Need help on Graphics and repaint
It's not a secret anymore!