This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to invoke a paint method in Frame?  RSS feed

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have tried a small program that extends a Frame class. the code is below, the paint method doesn't display the string, why? Any thing wrong? pl. help.


thanks in advance.
 
Basanth P Rangadhol
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai...
the string was drawn, but was not visible... and also while overriding paint method, it is better to paint the super.paint(graphics g)... also, try avoiding paint() method... you can ue paintComponents() method...

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Basanth,

I tried your code,

public void paint(Graphics g) { super.paint(g); g.drawString( ms, 20,40); }

but didn't work. I still can't see the string display on the frame.

Anyother way of doing?

regards,
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there!

Very sorry for the silly mistake... the co-ordinates were too small, hence the message got printed on the TitleBar. After changing it to higher values the message got displayed.

the code i tried is:
=========================


regards to all,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!