import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
导入 javax.swing.JFrame;
import javax.swing.JOptionPane;
public class MessageDialog {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setLocationRelativeTo(null);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
JButton leave = new JButton(退出”);
window.add(exit);
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成的方法 stub
int return = showConfirmDialog();
if(return==0)//如果点击的按钮是 yes”
System.exit(0);
}
});
window.add(exit);
window.pack();
}
static int showConfirmDialog(){
return JOptionPane.showConfirmDialog(
null,
你确定要退出吗?”,
退出”,
JOptionPane.YES_NO_OPTION);
}
}
Please disable your ad blocker and refresh the window to use this website.