以下是我的挥杆程序代码
import javax.swing.*;
import java.awt.event.*;
public class OptionPaneExample extends WindowAdapter{
JFrame f;
OptionPaneExample(){
f=new JFrame();
f.addWindowListener(this);
f.setSize(300, 300);
f.setLayout(null);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
int a=JOptionPane.showConfirmDialog(f,"Are you sure?");
if(a==JOptionPane.YES_OPTION){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
在输出中我只想要两个按钮是和否。但是在输出中我得到了取消按钮。如何删除,请告诉我。
I'm getting this output. But i want only two buttons Yes and No.
答案 0 :(得分:1)
尝试:
int a = JOptionPane.showConfirmDialog(f, "Your Message", "Title on Box", JOptionPane.YES_NO_OPTION);
答案 1 :(得分:1)
int a=JOptionPane.showConfirmDialog(f,"Are you sure?", "Question", YES_NO_OPTION );
请阅读JOptionPane
的文档。