呼,答案出來了~~~~!!!
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
class EX054 extends Frame {
Image ImageObj;
int IWidth, IHeight;
int inTop, inLeft;
public static void main(String[] args)
{ EX054 obj= new EX054(); obj.repaint(); }
public EX054() {
try
{
ImageObj= Toolkit.getDefaultToolkit().getImage(new java.net.URL("http://163.17.140.55/2003Java/JPEG2000/cafe.pgm"));
}
catch(java.net.MalformedURLException e){}
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(ImageObj,1);
try { if (!tracker.waitForID(1,10000)){
System.out.println("Load error!");
System.exit(1); }
} catch (InterruptedException e) { System.out.println(e); }
setVisible(true);
IWidth= ImageObj.getWidth(this);
IHeight= ImageObj.getHeight(this);
inTop= getInsets().top;
inLeft= getInsets().left;
setSize(inLeft+IWidth, inTop+IHeight);
setTitle("Read Image and Show Image");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); }});
}
public void paint(Graphics g) {
if (ImageObj != null)
g.drawImage(ImageObj,inLeft,inTop,this);
}
}
|