• Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint() method? Something's fishy...  RSS feed

 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me why I have a blank applet instead of my name in increasing size down the applet? Is it my use of the repaint() method?

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are writing several Strings over one another, and they are falling off the top of the Applet. Try changing from x position to y position.

[edit]Spelling corrections[/edit]
[ April 19, 2007: Message edited by: Campbell Ritchie ]
 
Andrei Pat
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have done several things wrong there:
1) repaint() calls paint() so this is an infinite recursivity problem
2) there is no delay in between the repaints, so will not see an animation
3) custom painting in the JApplet does not work, because the contentPane will hide what you paint
4) the animation has to be done in a separate thread

Maybe you should read this first
Here's a piece of code that works:


Later edit: I assumed you want an animated text. If you do not need the animation, you can paint everything inside the paintComponent and remove the animation thread. Still, overriding the paint method of the JApplet does not work, and NEVER call repaint() from paint() on the same component

[ April 19, 2007: Message edited by: Andrei Pat ]
[ April 19, 2007: Message edited by: Andrei Pat ]
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Andrei Pat.

I got it to work by simply altering the position, but you are quite correct there is an infinite recursion.
 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, just taking out the repaint() and changing x to y did it. I forgot that repaint() called paint! Thanks!

-Patrick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!