How can i paint the frame??

in my java prg,
i am trying to paint something in
the frame. when i use,
  public void paint(Graphics g)
 {
 g.drawString("kjt",20,20);
  }
such a sequence doesnt give any
errors or warnings, but the string
'kjt' doesnot printed. when i try
to set the background color in paint
i is nicely working. but the string
is not displayed.
Why?? can u explain please??
all the times i am invoking the paint
message.
prabhuramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
set the color and the font

g.setColor(Color.white);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.setfont(getFont());
g.drawString("kjt",20,20);
0
aviaviCommented:
maybee u didn't declare a layout?

in jdk 1.0:
setlayout(nul);
in jdk1.1:
setLayout(new xyLayout());
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sgomsCommented:
try,

import java.awt.*;

class WriteOnFrame extends Frame{
     WriteOnFrame(){
                    setSize(300,200);
                        setTitle("String drawn!");
                        repaint();
             }
             public void paint(Graphics g){
                    g.drawString("Hello.. this is a Frame!",75,100);
             }
             public static void main(String args[]){
                   (new WriteOnFrame()).setVisible(true);
             }

}

-sgoms
0
dvd99Commented:
Draw the graphics in a canvas.
0
bhatdCommented:
Try adding a Panel to the contentPane and then override paint and draw in the panel.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.