我已经开始使用Eclipse学习Java,并且我更改了main函数,以将两个字符串传递给同样更改的GUI构造函数(之前没有传递任何内容)。
GUI现在不会在屏幕上弹出,但是可以从屏幕底部的任务栏访问。我只是想知道为什么会这样?我在下面粘贴了缩短的代码。
我已经尝试过多次,并尝试在网络上查找关键字问题。
public class MainButton
{
public static void main(String[] args)
{
String A = "title"; String B = "Button";
Agui a = new Agui(A,B);
//BEFORE Agui a = new Agui();
}
}
import javax.swing.*;
public class Agui extends JFrame
{
//BEFORE public Agui()
public Agui(String A, String B)
{
setTitle(A);
setSize(400, 400);
// Create JButton and JPanel
JButton button = new JButton(B);
JPanel panel = new JPanel();
// Add button to JPanel
panel.add(button);
// And JPanel needs to be added to the JFrame itself!
this.getContentPane().add(panel);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
不弹出屏幕底部的任务栏弹出弹出窗口,并了解为什么会出现此问题的逻辑,将是很好的选择。