Jump to content

[Java] Creating an image outside of paint()..


Cless

Recommended Posts

I'm relatively new to Java programming, to a certain extent. More specifically, new to programming applets. I used to do Java programming somewhat about three years ago, but not too regularly.

 

Anyway, I had attempted to create an image and display it to the screen outside of the paint() function. It is in a manually created method called "update_text".

 

m_letter1= getImage(getCodeBase(), ut_character);

m_graphics1.drawImage(m_letter1, 21, 21, this);

 

This executes at the end of the update_text method. However, I get a NullExceptionError when it runs, and therefore the image is not displayed. Here (before the above code is executed), apparently m_letter1 and m_graphics1 are null. ut_character is not. After executing the above code, only m_graphics1 is null.

 

Outside of the update_text method, I defined the graphics and image variables (m_letter1 and m_graphics1):

 

private Image m_letter1;
private Graphics m_graphics1;

 

This is the error I get:

 

Exception in thread "Thread-5" java.lang.NullPointerException
at base.Main.update_text(Main.java:113)
at base.Main.run(Main.java:156)
at java.lang.Thread.run(Thread.java:619)

 

Main.java:113: m_graphics1.drawImage(m_letter1, 21, 21, this);

 

Main.java.156: update_text();

 

Anyway, I was wondering if there was a way to fix this. I can't necessarily use the paint method, I'm pretty sure, since I don't want all of this displayed exactly at run time.

 

Any help would be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/202702-java-creating-an-image-outside-of-paint/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.