• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics g nullpointerexception problem  RSS feed

 
Vladimir Monakhov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright,


I get a nullpointerexception on "g"

I want a image to be drawn not when I start up the program but when I click on the mouse.

To do so:



If I change this:

to this:


I cant compile because of the mouseEvent.

How do I fix this?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Vladimir and welcome to the Ranch! If that code is inside a class extending a Component or JComponent, you're going about this the wrong way. Never use getGraphics() of a Component -- or at least, not until and unless you thoroughly understand the painting processes involved. Go through the tutorial on Performing Custom Painting and learn how to do it the correct way.

If you have any other questions regarding GUIs and painting, please post them in the Swing / AWT / SWT section.
 
Vladimir Monakhov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Hello Vladimir and welcome to the Ranch! If that code is inside a class extending a Component or JComponent, you're going about this the wrong way. Never use getGraphics() of a Component -- or at least, not until and unless you thoroughly understand the painting processes involved. Go through the tutorial on Performing Custom Painting and learn how to do it the correct way.

If you have any other questions regarding GUIs and painting, please post them in the Swing / AWT / SWT section.


Yea, got help by a guy. I wasn't thinking it trough enough. But thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!