• Post Reply Bookmark Topic Watch Topic
  • New Topic

loading an image

 
K Wolfe
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);
}
}
 
Roy Ben Ami
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!