Java NetBeans永远地“使用”;“正在运行…”;不会编译

Java NetBeans永远地“使用”;“正在运行…”;不会编译,java,netbeans,jframe,Java,Netbeans,Jframe,这是我的Java代码: import javax.swing.JFrame; public class Objects { public static void main(String[] args) { JFrame window = new JFrame(); window.setVisible(true); } } 当我试图运行该文件时,它不会编译(它只是永远坐在那里“running…”)。当我删除最后一行时,它会编译 有什么想法吗

这是我的Java代码:

import javax.swing.JFrame;

public class Objects {
    public static void main(String[] args) {

        JFrame window = new JFrame();

        window.setVisible(true);
    }
}
当我试图运行该文件时,它不会编译(它只是永远坐在那里“running…”)。当我删除最后一行时,它会编译

有什么想法吗

我试图学习以下课程:


事实上,它确实成功地编译了。它之所以说“正在运行…”是因为当您调用
setVisible(true)
时,您的窗口变为可见,并且程序会一直运行直到关闭

听起来好像你看不到窗口,即使你创建的窗口变得“可见”

尝试添加

// Set the size of the window.
window.setSize(600, 400);

// Position the window in the middle of the screen.
window.setLocationRelativeTo(null);

// End the application when X is pressed.
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

调用
setVisible(true)
之前。这将确保您可以看到您创建的窗口。

它实际上已成功编译。它之所以说“正在运行…”是因为当您调用
setVisible(true)
时,您的窗口变为可见,并且程序会一直运行直到关闭

听起来好像你看不到窗口,即使你创建的窗口变得“可见”

尝试添加

// Set the size of the window.
window.setSize(600, 400);

// Position the window in the middle of the screen.
window.setLocationRelativeTo(null);

// End the application when X is pressed.
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
调用
setVisible(true)
之前。这将确保您可以看到您创建的窗口