gpt4 book ai didi

java - Java Web Start 小程序/应用程序中的 InvocationTargetException

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:00 24 4
gpt4 key购买 nike

作为引用,我之前问过一个关于将我的 Java 应用程序本质上转换为 applet 的错误的问题。好吧,我被建议尝试 JavaWebStart,但我仍然遇到这种方式的问题,所以我决定创建一个新问题。

这是我引用的问题:java.lang.reflect.invocationtargetexception error in applet

我假设我假设我有某种结构错误,关于如何设置 JavaWebStart 应用程序,因为我已经在本地测试我的代码作为 jar 文件并且没有运行它的错误。

这是一个示例页面: http://fogest.com/java_example/

最佳答案

您的代码似乎确实有一个main(String[] args),正如我们在您上一个问题中讨论的那样。因此,它可能就像更改一样简单:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://fogest.com/java_example" href="">
<information>
<title>Launch applet with Web Start</title>
<vendor>Foo Bar Inc.</vendor>
<offline-allowed/>
</information>
<resources>
<j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="physics.jar" main="true" />
</resources>
<applet-desc
name="Physics" main-class="main.MainGame"
width="300" height="200">
</applet-desc>
<update check="background"/>
</jnlp>

类似于:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://fogest.com/java_example" href="">
<information>
<title>Launch applet with Web Start</title>
<vendor>Foo Bar Inc.</vendor>
<offline-allowed/>
</information>
<resources>
<j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="physics.jar" main="true" />
</resources>
<application-desc main-class="main.MainGame">
</application-desc>
<update check="background"/>
</jnlp>

注意事项

  1. 我没有验证任何一个 JNLP,但你应该。我写了JaNeLA正是因为这样做。
  2. 应在 EDT 上创建和更新 Swing GUI。参见 Concurrency in Swing (尤其是关于“初始线程”的部分)以获取更多详细信息。
  3. 这是一个基于框架的 SSCCE。

import java.awt.*;
import javax.swing.*;

public class MainGame {
public static final String NAME = "Physics - Projectile Motion Example";
public static final int HEIGHT = 160;
public static final int WIDTH = HEIGHT * 16 / 9;
public static final int SCALE = 4;

public MainGame() {
run();
}

public void run() {
JFrame frame = new JFrame(MainGame.NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());


JPanel options = new JPanel();
options.add(new JLabel("Options"));
JPanel game = new JPanel();
game.add(new JLabel("Game"));

frame.setSize(new Dimension ( WIDTH * SCALE, HEIGHT * SCALE ));

frame.add(game, BorderLayout.CENTER);
frame.add(options, BorderLayout.SOUTH);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}

public static void main(String[] args) {
new MainGame();
}
}

关于java - Java Web Start 小程序/应用程序中的 InvocationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17139495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com