gpt4 book ai didi

java - 如何操作按钮在 Java 中为 GUI 打开新 Pane

转载 作者:行者123 更新时间:2023-12-04 06:07:45 26 4
gpt4 key购买 nike

我正在创建一个 GUI,其中我的主页有一个标记为“欢迎使用面板”的按钮

关键是当你按下这个按钮时,它会导航到一个新页面,在那里我会有其他功能。我唯一的问题是我不知道语法或单击按钮时如何导航到新页面。

最佳答案

JButton btn = new JButton("Welcome to the Panel");
btn.setActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// Here you open the other window. You can use JFrame, JOptionPane or JDialog
}
});

关于java - 如何操作按钮在 Java 中为 GUI 打开新 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8156253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com