按理说JDK不是问题,我怀疑是浏览器的安全级别限制了,可是我调到最低,看到的东西也是一个红叉。不明白为什么会出现这种情况。但用Eclipse可以运行出来。
<html> 
<body> 
<APPLET CODE="HelloWorld.class" width=150 height=200> 
</APPLET> 
</body> 
</html> 
其中HelloWorld.class这个文件是和html页面同时放在e盘根目录下的。
HelloWorld的代码是网上找的,很简单的:import java.applet.*;
import java.awt.Graphics;public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("HelloWorld", 25, 50);
}
}

解决方案 »

  1.   

    问题解决了,是JDK没有装好。还有个问题:
    public static String getMac() {
    String command = "ipconfig /all";
    String mac = null;
    Process proc;
    try {
    proc = Runtime.getRuntime().exec(command);
    BufferedReader reader = new BufferedReader(new InputStreamReader(
    proc.getInputStream()));
    String line = null;
    while ((line = reader.readLine()) != null) {
    if (line.indexOf("Physical Address") != -1) {
    mac = line.substring(line.indexOf("Physical Address") + 36,
    line.length());
    break;
    }
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    return mac;
    } public void paint(Graphics g) {
    String mac = HelloWorld.getMac();
    // g.drawString("HelloWorld", 25, 50);
    g.drawString("[" + mac + "]", 25, 50);
    }
    这是我的applet程序。我在Eclipse下运行时可以获取MAC地址,没有问题,放到IE中就出现问题了:没有反应。原来还可以在页面上显示HelloWorld,但是我注掉了,改用显示MAC地址,就不行了。 
    以下是控制台的内容: 
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute) 
    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.checkExec(Unknown Source) 
    at java.lang.ProcessBuilder.start(Unknown Source) 
    at java.lang.Runtime.exec(Unknown Source) 
    at java.lang.Runtime.exec(Unknown Source) 
    at java.lang.Runtime.exec(Unknown Source) 
    at HelloWorld.getMac(HelloWorld.java:16) 
    at HelloWorld.paint(HelloWorld还有我在Eclipse中运行多次applet程序以后就会出现下面的错误: 
    java.lang.NullPointerException: component argument pData不知是什么原因~~~
      

  2.   

    补充一下,运行没有出错,是在关闭applet程序时出现java.lang.NullPointerException: component argument pData错误。
      

  3.   

    这是你Applet的安全机制导致的。你需要设置Applet的安全。