java - 向 GUI 构造函数添加参数会停止 GUI 弹出
问题描述
我已经开始使用 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);
}
}
无需转到屏幕底部的任务栏就可以弹出窗口,并了解为什么会出现此问题的逻辑,这将是很棒的。
解决方案
推荐阅读
- javascript - State ValueChange 无法重新渲染组件
- swift - 范围限制的“无法推断通用参数 'T'”
- spring - 包含的 gradle 构建中的 Spring 依赖管理
- javascript - adobe JavaScript 在句点上拆分字符串
- regex - 匹配第 2 和第 5 个字符的正则表达式
- excel - 将 ActiveWorkbook 作为电子邮件附件发送
- javascript - 我怎样才能让这个小的 javascript 倒数计时器工作?
- reactjs - 使用 next js 在monorepo的共享模块中出现意外错误
- c - socket_setup 调用 fcntl(sock, F_SETFD, FD_CLOEXEC) 时出现问题
- windows - Windows CMD 批处理脚本 - 如何避免剪切标记“!” 在循环