drawString
I an confused. drawString is a n abstract method in java.awt.Graphics, Then how does it functiom. in thye folowing program
import javax.swing.* ;
import java.awt.* ;
public class DisplayApplet extends JApplet
{
public void paint (Graphics g)
{
g.drawString("This is displayed by the paint method", 20, 20) ;
}
}
My question - where is drawString actuall implemented.
Thanks in advamce
[458 byte] By [
tshota] at [2007-10-3 3:31:49]

> I an confused. drawString is a n abstract method in
> java.awt.Graphics, Then how does it functiom.
Since Graphics is abstract, there can't be a Graphics instance to call drawString() on, correct? So it must be any subclass.
> My question - where is drawString actuall
> implemented.
From an OO point of view: none of your business. If you really do care:
System.out.println(g.getClass().getName());
What i have laernt - according to that abtract method is a method with no implementation abd we as auser of tha method have to privide the implementation.
But in mt sctip, drawString is not detaied anywhere bit its till works.
So i wanted to know (actually) that how is drawString is working withoud being implmented in any of the classes.
And where shoid i put getClass().getName() ti get info on drawString()
-
tshota at 2007-7-14 21:25:53 >

CeciNEstPasUnProgrammeur is right
if you run the getClass().getName() on the Graphics object, you will see that it is a sun.java2d.SunGraphics2D object. it is located in rt.jar.
import java.awt.Graphics;
import javax.swing.JApplet;
public class DisplayApplet extends JApplet {
public void paint(Graphics g) {
System.out.println(g.getClass().getName());
g.drawString("This is displayed by the paint method", 20, 20);
}
}
So i wanted to know (actually) that how is drawString is working withoud being implmented in any of the classes.
Of course it's implemented! In one of the subclasses. Where? You shouldn't care, that's why it's OO.
If you really must know, well, you have the answer above.
P.S: you could also implement drawString() yourself, maybe doing so will show you how other subclasses actually implement it