600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > java jdialog 取消关闭按钮_的JDialog关闭按钮事件

java jdialog 取消关闭按钮_的JDialog关闭按钮事件

时间:2022-03-14 16:44:19

相关推荐

java jdialog 取消关闭按钮_的JDialog关闭按钮事件

将WindowListener添加到JDialog,并在windowClosed设置布尔值或关闭时的东西。也有一个buttonClicked布尔值,如果他们点击了按钮,它将是真实的,如果他们点击窗口顶部的退出按钮,它将是错误的。

boolean closed;

boolean buttonClicked;

JButton exitbutton;

JDialog dialog;

...

public void actionPerformed(ActionEvent arg0) {

buttonClicked = true;

dialog.dispose();

}

...

dialog.addWindowListener(new WindowListener() {

public void windowActivated(WindowEvent arg0) {

// Do nothing

}

public void windowClosed(WindowEvent arg0) {

closed = true;

if(buttonClicked) {

//They cliked the button to close it.

} else {

// They didn't click the button, they clicked exit in the top right corner of screen.

}

}

public void windowClosing(WindowEvent arg0) {

// Do nothing

}

public void windowDeactivated(WindowEvent arg0) {

// Do nothing

}

public void windowDeiconified(WindowEvent arg0) {

// Do nothing

}

public void windowIconified(WindowEvent arg0) {

// Do nothing

}

public void windowOpened(WindowEvent arg0) {

// Do nothing

}

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。