java - 无法使用Eclipse 3.6执行java GUI程序

标签 java eclipse user-interface ubuntu

我无法在ubuntu 11.04下的eclipse 3.6中执行java gui程序。当我单击“运行为 Java Application”时什么都没发生。当我切换到console时就在那里<terminated>

那该怎么办呢。我已经安装了jdk 1.6.0_25

我的系统中还安装了一个openjdk。但我不知道如何使用 eclipse 进行配置。

这是程序:

public class AnimWallpaper {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        UserInterface mainWindow = new UserInterface();
    }
}



import java.awt.Color;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class UserInterface extends Frame {

    /**
     * Serial version Id
     */
    private static final long serialVersionUID = 7925308422918335055L;
    public UserInterface(){
        setTitle("Animated Wallpaper");
        setSize(400, 300);

        Container con = new Container();

        con.setBackground(new Color(83, 68, 235));



        add(con);
        addWindowListener(new WindowAdapter() {
            public void closingEvent(WindowEvent e){
                System.exit(0);
            }
        });
    }
}

这两个类位于不同的文件和同一个包 com.anim 中

提前致谢:)

最佳答案

您需要设置您的窗口visible为了让它显示出来。 添加行 setVisible(true);

关于java - 无法使用Eclipse 3.6执行java GUI程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188470/

相关文章:

java - 用逗号分隔BigInteger结果

java - Clojure deftype 引用其他类型

javascript - 无法导入html中的js文件

c++ - 链接来自另一个文件的函数时,Qt 上的错误 LNK 2019

java - InterruptedException 未被捕获

java - Primefaces 3.0.M3 命名空间 url 不起作用

java - Eclipse 导出为可执行 jar NullPointerException

java - 谷歌眼镜中的 Hello World

java - 为什么我创建的随机矩形没有出现在我的游戏中?

ios - UI 不会立即更新 iOS