Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Something wrong with my paint() method  RSS feed

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I don't know why but for the past few days I have been facing a queer problem in my programs. This time when I call the paint() method via repaint() it does not get called except for the first time.
Here is my code:


Also when I try to initialize the Graphics object with the help of the Image object I get an exception that its null. if you have any questions to ask me in regard to this please do so because I may not have been clear.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does your class have a repaint method? You aren't extending or implementing anything to give you that method, or to create a Graphics object for you. Is there code missing?

Mark
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
The class extends JFrame, I forgot to paste it. BUT I tried something and it worked but I don't know why?

in the constructor


I shifted the lines into the following way and it worked but why I don't know:
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shyam Murarka:
Dear Readers,
The class extends JFrame, I forgot to paste it. BUT I tried something and it worked but I don't know why?

in the constructor


I shifted the lines into the following way and it worked but why I don't know:


Java usually ignores whitespace (such as tabs and spaces), so indenting your code would not make a difference. You must have inadvertently changed something else in order for it to work.

Layne
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shyam, the two code snippets are not the same! Take a look at when you call setVisible and repaint.

Anyway, moving to our Swing forum...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!