2017-09-17 86 views
0

以下是我的挥杆程序代码确认对话框,有两个按钮

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.

+2

我建议看看[如何使用对话框](https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html) – MadProgrammer

回答

1

尝试:

int a = JOptionPane.showConfirmDialog(f, "Your Message", "Title on Box", JOptionPane.YES_NO_OPTION); 
+0

我明白了..谢谢 –

1
int a=JOptionPane.showConfirmDialog(f,"Are you sure?", "Question", YES_NO_OPTION); 

请阅读JOptionPane的文档。