开发者

Applet does not show up in browser

I have the following applet开发者_StackOverflow中文版: http://s1.picofile.com/file/6922766596/Game.jar.html

and my applet before jar :http://s1.picofile.com/file/6923855130/Game_III_Applet.7z.html

I have embedded it as follows in my HTML page:

<applet code="FrameS.class" archive="Game.jar" width=1000 height=800></applet>

However, nothing shows in my MSIE browser. How is this caused and how can I solve it?


Caused by: java.security.AccessControlException: 
    access denied (java.io.FilePermission back.jpg read)

Applets should use URLs to access their resources. The resource can be in a Jar file (such as the 4.7 meg Game.jar) that is on the applet's run time class-path (i.e. mentioned in the archive attribute) or loose on the same server as the applet (or the applet's codebase).

In the first case, an URL can be formed using ..

URL urlToPic = this.getClass().getResource("images/back.jpg");

.. where the image is located in the images path of the Jar.

In the 2nd case, an URL can be formed relative to the codebase or document base of the applet. E.G.

URL urlToPic = new URL(this.getDocumentBase(), "images/back.jpg");

.. where the image is in the images sub-directory of the directory containing the applet.

The methods that accept a File parameter will often also accept an InputStream or URL.


We cannot test it when you provide just the .jar package

please provide more, or solve it yourself by looking into java error console

for example I got this exception, saying I'm missing back.jpg image resource

java.lang.reflect.InvocationTargetException
at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(DeployAWTUtil.java:116)
at sun.plugin2.applet.Plugin2Manager.runOnEDT(Plugin2Manager.java:3542)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3073)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1498)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission back.jpg read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:871)
at sun.awt.SunToolkit.getImage(SunToolkit.java:885)
at apple.awt.CToolkit.getImage(CToolkit.java:934)
at FrameS.<init>(FrameS.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.plugin2.applet.Plugin2Manager$13.run(Plugin2Manager.java:3061)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:677)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:638)
at java.awt.EventQueue$1.run(EventQueue.java:636)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:647)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception: java.lang.reflect.InvocationTargetException


Please use the object tag when embedding applets in IE , here is a php function which outputs applet embedding code based on a browser you will see different browsers are handled differently -

function getApplet($jarFile,$className,$params = array(),$width=1,$height=1,$name='japplet')
{
$retVal = "";

$useApplet = 0;
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (stristr($user_agent, "konqueror") || stristr($user_agent, "macintosh") || stristr($user_agent, "opera")) {
    $useApplet = 1;
    $retVal = sprintf('<applet name="%s" id="%s" archive="%s" code="%s" width="%s" height="%s" MAYSCRIPT >',$name,$name,$jarFile,$className,$width,$height);
} else {
    if (strstr($user_agent, "MSIE")) {
        $retVal = sprintf('<object  name="%s" id="%s" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" style="border-width:0;" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_1-windows-i586.cab#version=1,4,1"  width= "%s" height= "%s">',$name,$name,$width,$height);
    } else {
        $retVal = sprintf('<object  name="%s" id="%s" type="application/x-java-applet;version=1.4.1" width= "%s" height= "%s">',$name,$name,$width,$height);
    }

    $params['archive'] = $jarFile;
    $params['code'] = $className;
    $params['mayscript'] = 'true';
    $params['scriptable'] = 'true';
    $params['name'] = $name;

}

foreach ($params as $var=>$val)
{
    $retVal .= sprintf('<param name="%s" value="%s">',$var,$val);
}

$retVal .= 'It appears you do not have Java installed or it is disabled on your system.<br />
                Please download it <a href="http://www.java.com/getjava/" class="link" target="_blank">here</a>';
if ($useApplet == 1) {
    $retVal .= '</applet>';
} else {
    $retVal .= '</object>';
}

return $retVal;
}

Object tag is what you need while embedding you applet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜