我有这个代码,但它不适用于按钮数组
JButton[] option = new JButton[2];
option[0].setText("sad");
option[0].setEnabled(true);
option[1].setText("sasdd");
option[1].setEnabled(true);
Object[] options = {option[0], option[1]};
int i = JOptionPane.showOptionDialog(null, "SADASD", "dfgdfgg", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
如果我使单个按钮工作完美,但我需要在阵列上控制其中一些。
答案 0 :(得分:2)
在设置值之前,您必须创建如下的JButton对象:
option[0] = new JButton();
option[1] = new JButton();
在创建数组后立即写下这一行。
答案 1 :(得分:0)
String[] options = {"Java", "C", "C++", "C#"};
String msg = "What is your favourite language";
String title = "Language Poll";
int result = JOptionPane.showOptionDialog(parentComponent, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if(result == options[0] {
//do some thing
} else {
.......
}
...