Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Graphics

 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am following the Java tutorial on 2D graphics and am playing with a class that creates a JFrame. Just for fun I want to print a message on a panel in the frame with the size of the frame after a user resizes the frame. As I have understood the tutorial, the method paintComponent is called eg. when the frame has been resized by a user.
However, in my code below, paintComponent seems to never be called after I resize the GUI. What am I missing ?

 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
paintComponent is called when you resize the frame. The String you draw always changes when you resize the window.
Or are you expecting something else to happen?
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrrgh. Maybe its the protected keyword. Will try.
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:Hi Michael,
paintComponent is called when you resize the frame. The String you draw always changes when you resize the window.
Or are you expecting something else to happen?


Nothing is written on the frame when I resize
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved. Sorry about the herring. Apparently I didnt run the class-file I thought I did. Had compiled from two different folders so was running the old classfile from before I added painting. Sorry.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a bug in the code that causes the window to be sized incorrectly. You'll find it by using @Override annotations wherever applicable :-) (you should get in the habit of using that everywhere, both to prevent bugs like this one from happening, and as a reminder to whoever reads the code in future to know that something gets overwritten).
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote: . . . something gets overwritten
Careful about spellings. You mean "overridden", surely?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic