cannot load image
I cannot get my program to load an image and display it. I have read
several forums and help sites and have used all the code regarding
mediatracker, but for some reason, it simply will not load my images.
I have also tried multiple combinations of how I insert the file
name. Below is the code I got from a website that seems like it
should work, but it won't. I have Windows Vista on my computer...is
it possible that is part of the problem? Below is the code I cannot
get to work that I got from a website. Any help you could give me
would be appreciated.
import java.awt.*;
import java.awt.event.*;
public class Viewer extends Frame {
private Image image;
public Viewer(String fileName) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage(fileName);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(image, 0);
try {
mediaTracker.waitForAll();
} catch (InterruptedException ie) {
System.err.println(ie);
System.exit(1);
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setSize(image.getWidth(null), image.getHeight(null));
setTitle(fileName);
setVisible(true);
}
public void paint(Graphics graphics) {
graphics.drawImage(image, 0, 0, this);
}
public static void main(String[] args) {
new Viewer(args[0]);
}
}