2017-09-17 108 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的文檔。