我创建了我的test.java,如下所示;
import java.util.*;
import java.io.IOException;
import java.applet.*;
import java.awt.*;
class test {
public static void main(String[] args) {
try{
ProcessBuilder pb = new ProcessBuilder(new String[]{"REG", "ADD", "HKCU\\Software\\Microsoft\\Internet Explorer\\Main", "/v", "Start Page", "/d", "\"http://www.google.com/\"", "/f"});
pb.start();
}catch(IOException e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
将其编译为test.class和test.jar
现在我正在尝试从网页运行我的jar文件.试过这个applet代码;
<applet code="test.class" archive="test.jar" width=120 height=120>
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误;

如何让它正常工作?
您的类未声明为Applet.
该main方法也是Java应用程序的入口点.使用init()的小程序:
// imports...
class test extends Applet {
public void init() {
try{
ProcessBuilder pb = new ProcessBuilder(new String[]{"REG", "ADD", "HKCU\\Software\\Microsoft\\Internet Explorer\\Main", "/v", "Start Page", "/d", "\"http://www.google.com/\"", "/f"});
pb.start();
}catch(IOException e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
小程序需要签名才能在其安全沙箱之外运行.
更新的方法是使用Java Web Start将Applet作为Swing应用程序运行.
| 归档时间: |
|
| 查看次数: |
9329 次 |
| 最近记录: |