Java 编写JFrame窗体右上角红色打叉关闭按钮的自定义事件
1个回答
展开全部
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestFrame {
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int value=JOptionPane.showConfirmDialog(null, "确定要关闭吗?");
if (value==JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
}
}
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestFrame {
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int value=JOptionPane.showConfirmDialog(null, "确定要关闭吗?");
if (value==JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询