Java WindowBuilder-& gt;导出为.jar(Runnable或Applet) [英] Java WindowBuilder -> Export as .jar (Runnable or Applet)
问题描述
我安装了Eclipse 3.7的WindowBuilder插件.
I installed the WindowBuilder Plugin for Eclipse 3.7.
我用各种方法(JFrame,JPanel,Application等)创建了一个非常简单的GUI.我试图将我的项目导出为可运行的JAR/.jar文件.我必须选择Main Class:它没有显示任何内容可供选择!导出仍然有效,但是文件无用.
I created a very simple GUI with various methods (JFrame, JPanel, Application etc.). I tried to Export my Project as a runnable JAR / a .jar file. I have to choose the Main Class: It does not show anything to select! The Export still works but the file is useless.
如何正确导出我的GUI类?
How do I export my GUI class properly?
似乎我需要一个主方法来使该类显示在主类列表中.但是问题是,WindowBuilder创建了一个像这样的类:
Seems I need a main method to make the class show up in the main class list. But the problem is, that WindowBuilder creates a class like this:
import javax.swing.JApplet;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class myGuiClass extends JApplet {
/**
* Create the applet.
*/
public myGuiClass() {
getContentPane().setLayout(null);
JButton btnMybutton = new JButton("myButton");
btnMybutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
System.out.println("Button pressed!");
}
});
btnMybutton.setBounds(10, 11, 91, 23);
getContentPane().add(btnMybutton);
}
}
如果我在此处创建主方法,则无法创建JApplet,因为它不允许在静态main方法中引用其非静态构造函数.至少我不知道该怎么做.那么我该如何将这个非常简单的一类程序导出到可运行的.jar或applet中呢?
If I create a main method here, I cannot create my JApplet, as it it not allowed to reference its non-static constructor in the static main method. At least I dont know how to do it. So how would I go about exporting this very simple one class program to a runnable .jar or an applet?
@Andrew:应用程序"是WindowBuilder-> Swing Designer菜单中的选项之一.实际上称为应用程序窗口",还有JApplet,JFrame,JDialog等.我想拥有一些可执行文件,可以将其带到另一台PC上或通过Web运行,因此我不必使用cmd窗口来处理粗暴的执行工作...
@Andrew: The "Application" meant one of the options in the WindowBuilder->Swing Designer menu. which is in fact called Application Window, and there are also JApplet, JFrame, JDialog and so on. I would like to have something executable that I can bring to another PC or run via web, so I dont have to deal with crude executing things with the cmd window...
推荐答案
尝试一下,这是在eclipse中创建jar或可运行jar的方法,项目中的所有外部库都将包含在内
Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
这篇关于Java WindowBuilder-& gt;导出为.jar(Runnable或Applet)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!