0
我下面的代码显示使用Java Swing的窗口。问题是当我在eclipse中运行代码时窗口不显示。当我将该文件作为可执行JAR文件导出并运行时,它可以正常工作。 eclipse中是否存在一个可阻止它从那里运行的bug?
如果有人能告诉我,我错过了什么,我将不胜感激。
package com.gui;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
public class Calculator {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Calculator window = new Calculator();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Calculator() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
//frame.setBounds(100, 100, 450, 300);
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lblNewLabel = new JLabel("Hello World");
frame.getContentPane().add(lblNewLabel, BorderLayout.NORTH);
}
}
适合我。确保日食知道它应该运行这个类,而不是一个'main'方法的其他类 – MadProgrammer 2014-09-02 03:25:34
是的,我在eclipse中运行配置指向正确的程序和类。它只是开始并说它正在运行,但没有窗口出现。 – 2014-09-02 03:27:59
添加一些工作'System.out.println'语句来跟踪进度,看它是否无法达到给定的点。尝试添加一个断点并对其进行调试 – MadProgrammer 2014-09-02 03:29:15