loading an image
hi i have done this coding in order to do image loading and then get
its height and width but it is showin an error that unable to load
image
could you plz check it and let me know where i m going wrong..
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import java.net.URL;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.Component;
public class Viewer extends JPanel{
private static Image image;
public Viewer(URL url) {
MediaTracker tracker;
image = Toolkit.getDefaultToolkit().getImage(url);
System.out.println("hi");
MediaTracker mt = new MediaTracker(this);
mt.addImage(image, 0);
try {
mt.waitForID(0);
} catch (InterruptedException e) {
System.err.println("Unexpected interrupt in waitForID!");
return;
}
if (mt.isErrorID(0)) {
System.err.println("Couldn't load image file " + url);
return;
}
int width = image.getWidth(this);
int height = image.getHeight(this);
if (width == -1 || height == -1)
System.out.println("Image width: "+width);
System.out.println("Image height"+height);
}
public static void main(String[] args) throws Exception {
String url =
"http://mt3.google.com/mt?n=404&;v=ap.14&x=1314&y=3177&zoom=4";
new Viewer(new URL(url));
}
}