为什么applet在嵌入HTML页面时不会与操纵杆交互?

时间:2013-09-11 15:04:19

标签: java applet

您好我需要制作一个Java Applet,与操纵杆交互: 因为我正在使用Jinput库,所以applet是一个外部 JAR!

我的小程序代码:

package test;
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Timer;
import java.util.TimerTask;

import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;


@SuppressWarnings("serial")
public class HelloWorld extends Applet 
{

    public Timer timer = new Timer();
    public  Controller ctr;

     public void init() 
     { 
         System.out.println("TF");
         ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
         Controller[] cs = ce.getControllers();

         System.out.println("comp lenght = " + cs.length);
         for(int i=0; i < cs.length; i++ ){
         Controller ctr0 = cs[i];
         System.out.println("TF - " + ctr0.getName());
         }
         ctr = cs[4];
         /*Component[] comp = ctr.getComponents();
         System.out.println("comp lenght = " + comp.length);
         for(int i=0; i < comp.length; i++ ){
             System.out.println("c=" + comp[i].getIdentifier() + " PData = " +  comp[i].getPollData());
         }*/

         timer.scheduleAtFixedRate(new TimerTask() {
              @Override
              public void run() {
                  System.out.println("----------------------");
                  ctr.poll();
                  Component[] comp = ctr.getComponents();
                 System.out.println("comp lenght = " + comp.length);
                 for(int i=0; i < comp.length; i++ ){
                     System.out.println("c=" + comp[i].getIdentifier() + " PData = " +  comp[i].getPollData());
                 }
              }
            }, 0, 2000);
         System.out.println("RG");
 // It is required but does not need anything. 
     } 

     public float get(){
         float number = 0;
//       ctr.poll();
//       Component[] comp = ctr.getComponents();
//       System.out.println("comp lenght = " + comp.length);
//       for(int i=0; i < comp.length; i++ ){
//           System.out.println("c=" + comp[i].getIdentifier() + " PData = " +  comp[i].getPollData());
//       }
         return number;// comp[0].getPollData();
     }

// This method gets called when the applet is terminated 
// That's when the user goes to another page or exits the browser. 
     public void stop() 
     { 
         System.out.println("STOP");
     // no actions needed here now. 
     } 


// The standard method that you have to use to paint things on screen 
// This overrides the empty Applet method, you can't called it "display" for example.

     public void paint(Graphics g) 
     { 
 //method to draw text on screen 
 // String first, then x and y coordinate. 
      g.drawString("Hey hey hey",20,20); 
      g.drawString("Hellooow World",20,40);

     }


//     private class MySecurityManager extends SecurityManager {
//          @Override
//          public void checkPermission(Permission perm) {
//              return;
//          }
//      }
} 

applet在Eclipse中运行良好,但是当我尝试输入HTML时:

错误(如下所示)显示在Java控制台中。

我在部署中遇到了什么问题?

Java错误控制台:

preloader: Construct preloader delegate
preloader: Setting default preloader and progress monitor for non JNLP applets
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@1502e07
preloader: Installing progress monitor true
preloader: Using preloader class: null com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter@347412
preloader: Using default preloader
preloader: Requested to use preloader class: null
preloader: Skipped all (0) download events prior to null
preloader: GrayBox: parent = sun.plugin2.main.client.PluginEmbeddedFrame[frame8,0,0,150x60,layout=java.awt.BorderLayout,title=,resizable,normal]
basic: Plugin2ClassLoader.addURL parent called for ip/HElloWorld3.jar
basic: Plugin2ClassLoader.addURL parent called for ip/HElloWorld3.jar
network: Cache entry not found [url: ip:8082/PSIM/HelloWorld3.jar, version: null]
network: Connecting ip/HElloWorld3.jar with proxy=DIRECT
network: Connecting ip/HElloWorld3.jar with proxy=DIRECT
network: Connecting ip/HElloWorld3.jar with cookie "locale=default"
preloader: Delivering: DownloadEvent[type=load,loaded=65536, total=200947, percent=1]
preloader: Start progressCheck thread
preloader: Delivering: DownloadEvent[type=load,loaded=131072, total=200947, percent=19]
preloader: Delivering: DownloadEvent[type=load,loaded=196608, total=200947, percent=38]
preloader: Delivering: DownloadEvent[type=load,loaded=200947, total=200947, percent=40]
network: CleanupThread used 6 us
network: Downloading resource: http:/HelloWorld3.jar
    Content-Length: 200.947
    Content-Encoding: null
network: Wrote URL http/HelloWorld3.jar to File C:\Users\O\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\3\369daf83-15e9243c-temp
security: The jar file isnt signed so the blacklist check will be skipped
security: Trusted libraries list file not found
cache: Create from verifier: JarSigningData{hasOnlySignedEntries=false, hasSingleCodeSource=false, hasMissingSignedEntries=false}
network: CleanupThread used 1 us
cache: Adding MemoryCache entry: ip:8082/PSIM/HelloWorld3.jar
security: Grant socket perm for ip:8082/PSIM/HelloWorld3.jar : java.security.Permissions@16ed23 (
 ("java.net.SocketPermission" "192.168.0.188" "connect,accept,resolve")
)

ruleset: Non-jnlp rule id: 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/HelloWorld3.jar
        main version: null
        isArtifact: true
ruleset: finding Deployment Rule Set for 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/HelloWorld3.jar
        main version: null
        isArtifact: true
ruleset: no rule applies, returning Default Rule
network: Created version ID: 1.7.0.40
network: Created version ID: 1.7.0.25
basic: Embedding dialogs not enabled in Configuration
ui: Pushing modality for applet ID 9 with dialog javax.swing.JDialog[dialog11,431,255,578x293,layout=java.awt.BorderLayout,TOOLKIT_MODAL,title=Security Warning,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,3,26,572x264,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
preloader: Stop progressCheck thread
ruleset: Non-jnlp rule id: 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/
        main version: null
        isArtifact: true
ruleset: finding Deployment Rule Set for 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/
        main version: null
        isArtifact: true
ruleset: no rule applies, returning Default Rule
security: SSV validation:
    running: 1.7.0_40
    requested: null
    range: null
    javaVersionParam: null
    Rule Set version: null
network: Created version ID: 1.7.0.40
network: Created version ID: 1.7.0.40
security: continue with running version
network: Created version ID: 1.7.0.40
network: Created version ID: 1.7
network: Created version ID: 2.2.40
security:  --- parseCommandLine converted : 
into:
[]
preloader: Delivering: AppletInitEvent[type=CallConstructor]
preloader: Start progressCheck thread
cache: Reading Signers from 5 ip:8082/PSIM/HelloWorld3.jar | C:\Users\O\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\3\369daf83-15e9243c.idx
network: No certificate info for unsigned JAR file: ip:8082/PSIM/HelloWorld3.jar
cache: Done readSigners(ip:8082/PSIM/HelloWorld3.jar)
cache:  Read manifest for ip:8082/PSIM/HelloWorld3.jar: read=45 full=45
basic: Applet loaded.
basic: Applet resized and added to parent container
preloader: Delivering: AppletInitEvent[type=CallInit]
ui: missing resource: java.util.MissingResourceException: Can't find resource for bundle com.sun.deploy.resources.Deployment, key PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 125927 us, pluginInit dt 426641362 us, TotalTime: 426767289 us
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 125927 us, pluginInit dt 426641362 us, TotalTime: 426767289 us
TF
security: Grant socket perm for ip:8082/PSIM/jars/jinput.jar : java.security.Permissions@8a717e (
 ("java.net.SocketPermission" "192.168.0.188" "connect,accept,resolve")
)

ruleset: Non-jnlp rule id: 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/jars/jinput.jar
        main version: null
        isArtifact: true
ruleset: finding Deployment Rule Set for 
        title: test.HelloWorld
        location: ip:8082/PSIM/
        main location: ip:8082/PSIM/jars/jinput.jar
        main version: null
        isArtifact: true
ruleset: no rule applies, returning Default Rule
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jinput.controllerPluginPath" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at net.java.games.input.DefaultControllerEnvironment$2.run(DefaultControllerEnvironment.java:91)
    at java.security.AccessController.doPrivileged(Native Method)
    at net.java.games.input.DefaultControllerEnvironment.getPrivilegedProperty(DefaultControllerEnvironment.java:89)
    at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:185)
    at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:62)
    at net.java.games.input.DefaultControllerEnvironment$4.run(DefaultControllerEnvironment.java:128)
    at java.security.AccessController.doPrivileged(Native Method)
    at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:126)
    at test.HelloWorld.init(HelloWorld.java:45)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
preloader: Delivering: ErrorEvent[url=ip:8082/PSIM/ label=access denied ("java.util.PropertyPermission" "jinput.controllerPluginPath" "read") cause=access denied ("java.util.PropertyPermission" "jinput.controllerPluginPath" "read")
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@1502e07
preloader: Preloader shutdown after ErrorEvent
preloader: Stop progressCheck thread
ui: Show default error panel
security: Reset deny session certificate store

0 个答案:

没有答案