java中JFrame 窗口关闭时,弹出一个对话框提示是否确定关闭
展开全部
public class Test extends JFrame
{
public Test() {
setSize(100, 200);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
int option= JOptionPane.showConfirmDialog(
Test.this, "确定退出系统? ", "提示 ",JOptionPane.YES_NO_CANCEL_OPTION);
if(option==JOptionPane.YES_OPTION)
if(e.getWindow() == Test.this)
{
System.exit(0);
}
else
{
return;
}
}
});
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
{
public Test() {
setSize(100, 200);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
int option= JOptionPane.showConfirmDialog(
Test.this, "确定退出系统? ", "提示 ",JOptionPane.YES_NO_CANCEL_OPTION);
if(option==JOptionPane.YES_OPTION)
if(e.getWindow() == Test.this)
{
System.exit(0);
}
else
{
return;
}
}
});
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
int selected = JOptionPane.showConfirmDialog(this, "是否退出");
if(JOptionPane.OK_OPTION == selected){
System.exit(0);
}
}
});
public void windowClosing(WindowEvent e){
int selected = JOptionPane.showConfirmDialog(this, "是否退出");
if(JOptionPane.OK_OPTION == selected){
System.exit(0);
}
}
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询