• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

loading an image

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand how to load an image into an applet... can someone tell me/show me the equivalent of loading an image into a swing application.... a simple translation of the following code would help.... thanks... Most of the examples I've stumbled across use an ImageIcon object that is loaded into a bufferedImage. Is that the only way to do it or is there a way of using a regular Image object in a swing app? I'm not trying for performance just yet...I'm just looking to understand the concepts of using images in swing applications as opposed to applets.
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
public class TestImage extends JApplet {

private Image img;

public void init () {
img = getImage(getCodeBase(), "test.jpg");
}

public void paint(Graphics g) {
g.drawImage(img, 50, 25, this);
}
}
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use this method to get the image - the rest is the same:
Toolkit.getDefaultToolkit().getImage("file name");
the Toolkit class is in the awt package.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!