java通过点击按钮创建了一个了一个新窗口,想通过该新窗口的按钮退出这个新框而不是整个程序,怎么做
答案:4 悬赏:10 手机版
解决时间 2021-01-22 19:22
- 提问者网友:棒棒糖
- 2021-01-22 14:03
java通过点击按钮创建了一个了一个新窗口,想通过该新窗口的按钮退出这个新框而不是整个程序,怎么做
最佳答案
- 五星知识达人网友:woshuo
- 2021-01-22 15:13
如果 button名叫A 新建窗口为 UI
this.A.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
new UI();
}
}追问dispose();把主窗口给隐藏了,我想的是隐藏或者关闭新窗口追答你这个写到你的新窗口就行。。。你这个写到你的新窗口就行。。。追问试过了啊,就是隐藏的主窗口追答Q727998536
this.A.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
new UI();
}
}追问dispose();把主窗口给隐藏了,我想的是隐藏或者关闭新窗口追答你这个写到你的新窗口就行。。。你这个写到你的新窗口就行。。。追问试过了啊,就是隐藏的主窗口追答Q727998536
全部回答
- 1楼网友:一叶十三刺
- 2021-01-22 17:29
不明白你的意思是什么
- 2楼网友:人间朝暮
- 2021-01-22 16:01
如果你不是通过线程创建的话 只能隐藏 不能关闭追问怎么做,dipose?
- 3楼网友:夜风逐马
- 2021-01-22 15:34
JFrame.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);
下面是setDefaultCloseOperation的JAVADOC
public void setDefaultCloseOperation(int operation)
Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:
The value is set to HIDE_ON_CLOSE by default. Changes to the value of this property cause the firing of a property change event, with property name "defaultCloseOperation".
Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.
DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
WindowConstants.DISPOSE_ON_CLOSE);
下面是setDefaultCloseOperation的JAVADOC
public void setDefaultCloseOperation(int operation)
Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:
The value is set to HIDE_ON_CLOSE by default. Changes to the value of this property cause the firing of a property change event, with property name "defaultCloseOperation".
Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.
DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯