• 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

Applet, How to get the image displayed PLEASE HELP

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

In my applet program, I have a problem in loading the image.

First I wrote

im1=getImage(getDocumentBase(),"C:/Documents and Settings/Mohan.RBCHRIT7/Desktop/HTML/Exercise1/images/Grocery.gif");
sugarPix = new JButton(new ImageIcon(im1));

When I run this, it gave me NullPointerException.(that means the image is not loaded to im1). Do I need to use drawImage in paint()? I searched google.com and found the code below:

Image redball = Toolkit.getDefaultToolkit().getImage ( "C:/Documents and Settings/Mohan.RBCHRIT7/Desktop/HTML/Exercise1/images/Grocery.gif");
sugarPix = new JButton(new ImageIcon(redball));

This code displayed the image without any problem. But, outside of applets you can use the getImage method from the default toolkit instead, like above.

Question:
How can I get the image in Applet, without using getDefaultToolkit()?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Applet forum for expert attention...

https://coderanch.com/t/257926/Applets/java/Applet-image-displayed-PLEASE-HELP
[ January 08, 2006: Message edited by: marc weber ]
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic