我安装了Eclipse 3.7的WindowBuilder插件。

我使用各种方法(JFrame,JPanel,Application等)创建了一个非常简单的GUI。我试图将我的项目导出为可运行的JAR / .jar文件。我必须选择Main Class:它没有显示任何内容可供选择!导出仍然有效,但是文件无用。

如何正确导出我的GUI类?

编辑:似乎我需要一个主要方法,以使该类显示在主类列表中。但是问题是,WindowBuilder创建了这样的类:

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);

    }
}


如果在此处创建main方法,则无法创建JApplet,因为它不允许在static main方法中引用其非静态构造函数。至少我不知道该怎么做。那么,如何将这个非常简单的类程序导出到可运行的.jar或applet中呢?

@Andrew:“应用程序”意味着WindowBuilder-> Swing Designer菜单中的选项之一。实际上称为应用程序窗口,还有JApplet,JFrame,JDialog等。
我想拥有一些可执行文件,可以将其带到另一台PC上或通过Web运行,因此我不必使用cmd窗口处理粗暴的执行工作...

最佳答案

试试这个,这是在eclipse中创建jar或可运行jar的方法,项目中的所有外部库都将包括在内

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 - Java WindowBuilder->导出为.jar(Runnable或Applet),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10826141/

10-11 22:46
查看更多