一个在网上获取图片的java程序..
imag.java文件..
import java.applet.*;
import java.net.*;
import java.awt.*;
public class imag extends Applet
{
Image imag;
URL imgur=null;
public void init()
{
try{
imgur= new URL("http://img.poco.cn/photo/20060721/94378020220060721123628_3.jpg");
}
catch(MalformedURLException e)
{
System.out.println("Can´t open the URL");
}
imag=getImage(imgur);
}
public void paint(Graphics g){
g.drawImage(imag,0,0,this);
}
}
test文件:
<html>
<head>
<title>Example</title>
</head>
<center>
<applet code=imag.class width=550 height=230>
</applet>
</html>
编译javac imag.java,没有错误..
运行appletviewer test..怎么不显示网络上的图片...给出这些提示..
java.security.AccessControlException: access denied (java.net.SocketPermission img.poco.cn resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at imag.init(imag.java:20)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
求大哥们给小弟点指导....该怎么做..
----------------解决方案--------------------------------------------------------
applet只能访问它所在的主机,不能到处访问别的地址
你写成application就可以了
----------------解决方案--------------------------------------------------------
好了 能用了 谢谢
----------------解决方案--------------------------------------------------------