使用 Netbeans 和 Swing 部署在 Netbeans 中创建的 Applet 时出错
我使用 NetBeans 创建了一个 Applet。我的合作伙伴使用 NetBean 的拖放 Swing 编辑器作为界面。当我右键单击小程序文件并单击“运行”时,它运行得非常好,没有异常或警告。但是,当我构建它并将 NetBeans 生成的 html 文件放在我的计算机上的 apache 服务器上并运行它时,它会抛出此异常。
以下是我将其部署到本地服务器 (~myHome/Sites/) 的步骤:
我单击“清理并构建”
我右键单击选项卡小程序源文件并选择“运行”。它在新窗口中打开并运行良好。 (它还创建了一个 Applet.html 文件用于测试,这就是我这样做的原因)
我运行 $ cp -r /build ~myHome/Sites 这会将用于测试的 html 文件和包含所有已编译类的类文件夹复制到我的站点文件夹
打开 Web 浏览器到该路径,它会给出错误并且不会加载
这是来自控制台的错误:
basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@316d3536
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 260792 us, pluginInit dt 255591692 us, TotalTime: 255852484 us
network: Cache entry not found [url: http://***.edu/~myHomeDirectory/build/classes/org/jdesktop/layout/GroupLayout$Group.class, version: null]
network: Connecting http://~myHomeDirectory/Sites/build/classes/org/jdesktop/layout/GroupLayout$Group.class with proxy=DIRECT
network: Connecting http://***.edu:80/ with proxy=DIRECT
network: Connecting http://***.edu/~myHomeDirectory/Sitesbuild/classes/org/jdesktop/layout/GroupLayout$Group.class with cookie
basic: Removed progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@316d3536
Exception in thread "thread applet-tab_interface/TabApplet.class-4" java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at tab_interface.Mediator.<init>(Mediator.java:26)
at tab_driver.TabDriver.<init>(TabDriver.java:86)
at tab_interface.TabApplet.init(TabApplet.java:69)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1640)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: org.jdesktop.layout.GroupLayout$Group
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 5 more
所以我想我的主要问题是:
我是否需要做一些额外的事情来部署和使用 NetBeans Swing 编辑器创建的小程序?
关于下一步应该做什么来解决这个问题有什么建议吗?我跟踪了该异常,它导致 Mediator 第 26 行...即:
gui = new AppletGUI();
该行是由 NetBeans Swing 编辑器创建的 GUI 类的构造函数。这是一些基本代码来显示发生了什么。 applet、GUI、GUIMediator 位于一个包中,而 TabDriver 位于其自己的包中。
class MyApplet extends Applet{
GUIMediator gui;
TabDriver driver;
init(){
driver = new TabDriver(...); // TabDriver creates a mediator
gui = driver.getMediator();
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (InterruptedException ex) {
...
} catch (InvocationTargetException ex) {
...
}
}
void createGUI(){
this.add(gui.getGUI()); // add JPanel to Applet
}
}
class TabDriver {
TabDriver (...) {
this.mediator = new GUIMediator(this);
}
}
class GUIMediator {
TabDriver driver;
JPanel GUI;
GUIMediator(TabDriver td) {
driver = td;
GUI = new TabGUI();
}
}
class TabGUI extends JPanel {
TabGUI() {
// super();
// init();
// initListeners();
// ...
}
}
请注意,TabGUI 中的所有内容都被注释掉,并且在 Web 浏览器中初始化 TabGUI 时它仍然会引发异常。
抱歉,这太长了。
谢谢你, -N
I've created an Applet with NetBeans. My partner used NetBean's Drag-and-Drop Swing editor for the interface. It runs perfectly fine with no exceptions or warnings when I right click on the applet file and click "run". However, it throws this exception when I build it and put the NetBeans generated html file on the apache server on my machine and run it.
Here is step by step what I'm doing to deploy it to my local server (~myHome/Sites/):
I click "clean and build"
I right click on the tab applet source file and select "run". It opens and runs fine in a new window. (It also creates a Applet.html file for testing, which is why I do it)
I run $ cp -r /build ~myHome/Sites
This copies the html file for testing and the class folder with all the compiled classes to my sites folderOpen a web browser to the path and it gives an error and doesn't load
Here is the error from the console:
basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@316d3536
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 260792 us, pluginInit dt 255591692 us, TotalTime: 255852484 us
network: Cache entry not found [url: http://***.edu/~myHomeDirectory/build/classes/org/jdesktop/layout/GroupLayout$Group.class, version: null]
network: Connecting http://~myHomeDirectory/Sites/build/classes/org/jdesktop/layout/GroupLayout$Group.class with proxy=DIRECT
network: Connecting http://***.edu:80/ with proxy=DIRECT
network: Connecting http://***.edu/~myHomeDirectory/Sitesbuild/classes/org/jdesktop/layout/GroupLayout$Group.class with cookie
basic: Removed progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@316d3536
Exception in thread "thread applet-tab_interface/TabApplet.class-4" java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at tab_interface.Mediator.<init>(Mediator.java:26)
at tab_driver.TabDriver.<init>(TabDriver.java:86)
at tab_interface.TabApplet.init(TabApplet.java:69)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1640)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: org.jdesktop.layout.GroupLayout$Group
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 5 more
So I guess my main questions are:
Is there something extra I have to do to deploy and applet created using the NetBeans Swing editor?
Any suggestions about what should do next to tackle this problem? I've followed the exception and it leads to Mediator line 26... which is:
gui = new AppletGUI();
That line is the constructor for the GUI class created by NetBeans Swing Editor. Here's some basic code to show whats going on. The applet, GUI, GUIMediator are in one package and the TabDriver is in its own.
class MyApplet extends Applet{
GUIMediator gui;
TabDriver driver;
init(){
driver = new TabDriver(...); // TabDriver creates a mediator
gui = driver.getMediator();
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (InterruptedException ex) {
...
} catch (InvocationTargetException ex) {
...
}
}
void createGUI(){
this.add(gui.getGUI()); // add JPanel to Applet
}
}
class TabDriver {
TabDriver (...) {
this.mediator = new GUIMediator(this);
}
}
class GUIMediator {
TabDriver driver;
JPanel GUI;
GUIMediator(TabDriver td) {
driver = td;
GUI = new TabGUI();
}
}
class TabGUI extends JPanel {
TabGUI() {
// super();
// init();
// initListeners();
// ...
}
}
Note that everything in the TabGUI is commented out and that it still throws the exception when TabGUI is initialized in a web browser.
Sorry this is so long.
Thank you,
-N
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来像
GroupLayout
不可用。由于它是 1.6 版本中的新功能,因此您可以检查已安装的 JRE。It looks like
GroupLayout
is unavailable. As it's new in version 1.6, you might check your installed JRE.