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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aviaviConnect With a Mentor Commented:
maybee u didn't declare a layout?

in jdk 1.0:
setlayout(nul);
in jdk1.1:
setLayout(new xyLayout());
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.