• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

createImage always returns null..

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure what is wrong here. createImage is always returning null. What's the usage of createImage ?
class Test extends Panel{
Image img;
public Test(){
img = createImage(100,100);
// After this, img is always null.
}
}
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you tell us which package contains the createImage()?
In java.awt.Graphics, we have drawImage().
Not sure whether createImage method is a built-in method...
If it is user defined, then createImage() should create an Image and return it to the caller. Otherwise, the object img will be null...
Uma
 
Rekha Rao
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
createImage is in java.awt package, defined in Component class.


 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you have to call createImage method on the Component object...
Uma
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry i was wrong. Since you had extended your class from Panel, it has inherited the createImage()...
 
Rekha Rao
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same thing works in the context of an applet, however.
Like in the code:
class Test extends Applet{

Image img;
public void init(){
img = createImage(100,100);
//Image is created it.
}
}
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before we call createImage(), it must have been realized, i.e., actually displayed.
The addNotify() of Component sets the component ready for display. After you call super.addNotify(), the component is realized.
Now modify your code like this and test...
class Test extends Panel{
Image img;
public void addNotify(){
super.addNotify();
img = createImage(100,100);
// After this, img is always null.
if(img != null)
System.out.println( "not null" );
else
System.out.println( "null" );
}
}
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic