gpt4 book ai didi

java - 向 JButton 添加关闭操作

转载 作者:行者123 更新时间:2023-12-01 14:49:55 25 4
gpt4 key购买 nike

我在弄清楚如何让 JButton 提示用户在关闭程序之前将内容保存在 JTextArea 中时遇到了一些麻烦。到目前为止,我有一些用于按钮关闭操作的代码,但即使这样似乎也不起作用......当我单击它时没有任何反应:

public void actionPerformed(ActionEvent event) {

if(event.getSource() == this.Quit)
this.dispose();
....

其余的是其他按钮的更多 else/if/try 语句。

我将我的类设置为扩展 JFrame 并实现 ActionListener,因此我的整个程序都在一个类中...可能不是一种非常简洁的编码方式,但我发现在分发之前将所有内容暂时放在这里会更容易一些函数到其他类中。

基本上,没有任何反应,我不知道如何添加保存提示并随后关闭它。任何帮助都会很棒!

最佳答案

Is there any way to tie this into a prompt to save before closing?

参见Closing an Application .

注意:您还可以将 ExitAction 添加到 JButton。然后,当您单击该按钮时,它将启动窗口的关闭。

关于java - 向 JButton 添加关闭操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14989847/

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