getImagepublic Image getImage(URL url)
Returns an Image object that can then be painted on the screen. The url that is passed as an argument must specify an absolute URL.This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.Parameters:url - an absolute URL giving the location of the image.getImage( "http://www.sina.com.cn...........gif" );
Returns an Image object that can then be painted on the screen. The url that is passed as an argument must specify an absolute URL.This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.Parameters:url - an absolute URL giving the location of the image.getImage( "http://www.sina.com.cn...........gif" );
public void init(){
//URL u = new URL("");
picture =getImage( "http://sina.com/abc.gif" );
}
public void paint(Graphics g){
g.drawImage(picture,25,25,this);
}
}
import java.applet.*;
import java.util.*;
import java.net.*;
public class HwImage extends Applet{
URL u = new URL("");
//("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
Image picture;
public void init(){
picture =getImage("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
}
public void paint(Graphics g){
g.drawImage(picture,350,350,this);
}}
这样还是错啊,我还没好好学applet,但明天要交了
import java.awt.*;
import java.applet.Applet;
import java.applet.*;
import java.util.*;
import java.net.*;public class HwImage extends Applet{
//URL u = new URL("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
//("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
public Image picture;
public void init(){
try{
URL u = new URL("http://www.pconline.com.cn/mobile/show/images/picpath/030623_530_135_01.jpg");
picture =getToolkit().getImage(u);
}catch(Exception e){}
}
public void paint(Graphics g){
g.drawImage(picture,1,1,this);
} public static void main(String args[]){
Frame f=new Frame("GetImage");
//f.addWindowListener(new WindowClose(f,true));
HwImage myApplet=new HwImage();
f.add(myApplet);
myApplet.init();
f.setSize(100,100);
f.setVisible(true);
myApplet.start();
}}
但是applet要装载在Frame 上 呵呵,我也是翻书才发现的 呵呵
编译成HwImage.java,运行,可以显示图片
用applet则没图片???~!!!!
怎么回事?
刚才我测试的时候······
Frame则没有权限的问题
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.*;
import java.util.*;
import java.net.*;public class HwImage extends Applet{
//URL u = new URL("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
//("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
public Image picture; public void init(){
try{
URL u = new URL("http://www.pconline.com.cn/mobile/show/images/picpath/030623_530_135_01.jpg"); picture =getToolkit().getImage(u);
}catch(Exception e){} }
public void paint(Graphics g){ g.drawImage(picture,1,1,this);
}
public static void main(String args[]){
Frame f=new Frame("GetImage"); Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
int screenHeight=d.height;
int screenWidth=d.width;
f.setSize(400,300);
f.setLocation(screenWidth/4,screenHeight/4);
f.setResizable(false);
f.setVisible(true); f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
HwImage myApplet=new HwImage();
f.add(myApplet);
myApplet.init();
myApplet.start();
f.show();
}
}
有什么好的解决方法吗?编写一个Applet小程序,用来动态获取网络上的各种资源,实现方法是在Applet小程序中加入一个线程,每隔一定的时间自动地到指定的网络站点上读取最新的内容。