• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getImage()

 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
applets have a method called getImage(URL, ImageName) but i want to call a similar method but i am using a class that extends JComponent and not JApplet.
please help!
z
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the api (javadocs) look up at the top of the page and click on the Index link, then the letter G and scroll down to the getImage listings. The Toolkit class has two plus some createImage methods.
 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but I got the following error on doing this and here it is:

non-static method getImage(java.net.URL) cannot be referenced from a static context

im0 = java.awt.Toolkit.getImage(new URL(str+"template/am1.jpg"));waitFor
Image(im0);
^
1 error
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need an instance of Toolkit to call getImage with. We can use the static method getDefaultToolkit to get the instance like so

or we can save it in a reference like this

There is some example code and more information in the MediaTracker api.
[ September 21, 2004: Message edited by: Craig Wood ]
 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However I still get the following error:

Tracker.java:101: unreported exception java.net.MalformedURLException; must be caught or declared to be thrown:

im0 = toolkit.getImage(new URL(urlStem+"template/am1.jpg"));waitForImage
(im0);
^
1 error

thanks for your patience.
z
 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!
Craig Wood you are a legend! I have been trying to solve that for weeks.
well done and thanks for the help.
z
 
jay kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by zack chancery:
applets have a method called getImage(URL, ImageName) but i want to call a similar method but i am using a class that extends JComponent and not JApplet.
please help!
z


use the ImageIcon class (javax.swing package) ,it has also got a function getImage() , u can use it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic