我正在使用 Swing 在 Java 中构建 GUI。制作按钮并添加它的代码如下:
//Create a button
JButton exitButton = new JButton("Exit");
exitButton.setSize(90, 40);
exitButton.setLocation(800, 450);
exitButton.setVisible(true);
//Adding components
window.getContentPane().add(exitButton);
当我运行该应用程序时,该按钮出现在整个窗口中,有时会按预期显示,有时不会出现。这是某种 java 错误还是我的sdk
. 如果您想知道它是什么类型的窗口,
//Create a window
JFrame window = new JFrame("First Window");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
window.setVisible(true);
window.setSize(1000, 550);
window.setLocation(150, 150);
这一切都在 static void main 之内。顺便说一句,我如何获得关闭窗口的按钮System.exit(0);
(我是初学者,这是我的第一个自写 GUI)