Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI and repaint()

 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an issue everytime I use mouse listener to call repaint().. It keeps printing like a snapshot of the Frame over the other one, only once.. Can someone help me figure out why? I don't understand what is happening enough to troubleshoot this issues. Thank you.

Here is my whole code if you want to copy and paste to run it. The issue lies in the TileCanvas sub class

 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind.. I fixed it. It was the way I was calling repaint.

I used frame.repaint(); and it resolved my issue.
 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited my code above.. using fram.repaint(); resets the page though, what I want to do, is is have it repaint the current grid which is in the TileCanvas class. but when i call just repaint().. i get a copy of the grid moved down a little painted over the original..

any ideas?
 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind I fixed it.. I just used, frame.repaint().. and then just refilled the grid on any refresh..

Felt good to fix it. ;)
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall move this to our GUIs forum, where we usually discuss such questions.

But why are you using a MouseListener in the first place? [Edit]I can now see why you want a MouseListener[/edit]
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jef Cho wrote:what I want to do, is is have it repaint the current grid which is in the TileCanvas class. but when i call just repaint().. i get a copy of the grid moved down a little painted over the original.

That's because you neglected to invoke the super implementation, which does the default painting of a blank background.Looks like you could benefit by going through the tutorial.
 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, gosh darn it. Yea I implemented a work around but for future projects I will be reading the tutorial shortly. The book im using is "Head First Java." So it really only scratches the surface on this topic.

Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic