Question

Hey guys I have a little issue here. I have a panel where I am drawing a string. This is a game so I keep redrawing the score in order to update it. However when I draw it again it is drawn on top of the previous score so it looked all garbled up. Any ideas how to fix this?

comp2d.drawString(GetScore(Score),ScoreX,ScoreY);

Was it helpful?

Solution

You need to redraw the background, before you paint the string. If this is an ordinary panel, you can redraw the background by a call to super.paintComponent(g) in your own paintComponent; however, since this is a game, I am going to guess that you have some other background you need to draw. Also, I would suggest that you use a JLabel, in lieu of using thedrawString command, if possible.

OTHER TIPS

You can try to use repaint() after comp2d.drawString().

when you call this comand: comp2d.drawString(GetScore(Score),ScoreX,ScoreY);

You should call this : comp2d.dispose()

because all operations with comp2d will be applied after .dispose()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top