Following is my swing program code
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();
}
}
In output i want only two buttons Yes and No. But in output i'm getting cancel button. How to remove that please let me know.
I'm getting this output. But i want only two buttons Yes and No.
尝试:
int a = JOptionPane.showConfirmDialog(f, "Your Message", "Title on Box", JOptionPane.YES_NO_OPTION);
int a=JOptionPane.showConfirmDialog(f,"Are you sure?", "Question", YES_NO_OPTION );
请阅读JOptionPane
的文档。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.