NetBeans 永久 "running..." 并且不会编译
NetBeans perpetually "running..." and will not compile
这是我的 Java 代码:
import javax.swing.JFrame;
public class Objects {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setVisible(true);
}
}
当我尝试 运行 文件时它没有编译(它只是永远与 "running..." 一起坐在那里)。当我删除最后一行时,它会编译。
有什么想法吗?
我正在尝试学习以下课程:
果然编译成功。它说 "running ..." 的原因是因为当你调用 setVisible(true)
你的 window 变得可见,并且程序保持 运行 直到它关闭。
听起来您看不到 window,即使您创建的 window 变成了 "visible"。
尝试添加
// 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)
之前。这应该确保您可以看到您创建的 window。
这是我的 Java 代码:
import javax.swing.JFrame;
public class Objects {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setVisible(true);
}
}
当我尝试 运行 文件时它没有编译(它只是永远与 "running..." 一起坐在那里)。当我删除最后一行时,它会编译。
有什么想法吗?
我正在尝试学习以下课程:
果然编译成功。它说 "running ..." 的原因是因为当你调用 setVisible(true)
你的 window 变得可见,并且程序保持 运行 直到它关闭。
听起来您看不到 window,即使您创建的 window 变成了 "visible"。
尝试添加
// 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)
之前。这应该确保您可以看到您创建的 window。