查看單個文章
舊 2003-10-08, 07:51 PM   #3 (permalink)
elevenoclock
榮譽勳章

勳章總數
UID -
在線等級:
文章: n/a
精華:
預設

呼,答案出來了~~~~!!!

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);
}
}
 
送花文章: 0, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖