Topic: 关于访问本地文件的问题 |
Print this page |
1.关于访问本地文件的问题 | Copy to clipboard |
Posted by: bullish Posted on: 2003-02-13 15:58 还是上个问题中我提到的程序, 我试着运行swing的一个例子, test.java 具体如下 =========================================== import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test extends JApplet { public void init() { Container contentPane = getContentPane(); Icon icon = new ImageIcon("swing.gif", "An animated GIF of Duke on a swing"); JLabel label = new JLabel("Swing!", icon, SwingConstants.CENTER); contentPane.add(label, BorderLayout.CENTER); } } 原先我在浏览器运行时遇到的找不到类的问题,通过安装plug-in已经解决,但出现了一个新问题,错误如下 java.security.AccessControlException: access denied (java.io.FilePermission swing.gif read) 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.checkRead(Unknown Source) at sun.awt.SunToolkit.getImageFromHash(Unknown Source) at sun.awt.SunToolkit.getImage(Unknown Source) at javax.swing.ImageIcon.<init>(Unknown Source) at Test.init(test.java:9) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 请问这是不是因为我访问了本地文件的原因?用什么办法可以解决?谢谢! |
2.Re:关于访问本地文件的问题 [Re: bullish] | Copy to clipboard |
Posted by: samx Posted on: 2003-02-14 09:00 你的代码没错,但缺了一些东西。你必须使用java.applet的getImage()来获得本地applet的地址。至于为什么,你可以查阅Java API文档。你添加这几句: import java.applet.*; . . . Image image=getImage(getCodeBase(),"swing.gif"); ImageIcon icon=new ImageIcon(image); JLabel label=new JLabel(icon); . . . 当然,你也可以访问网上可以访问的任何图象,你得使用java.net中的URL对象,并且要捕捉MalformedURLException异常。你自己可以试试! |
3.Re:关于访问本地文件的问题 [Re: bullish] | Copy to clipboard |
Posted by: bullish Posted on: 2003-02-14 10:50 好用了,非常感谢! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |