在最后一个JOptionPane上,我试图让程序返回一个对话框消息,告诉我用户按下了什么按钮。我该怎么做?
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(B1)){
JOptionPane.showMessageDialog(B1, "Player 1 pressed!");
String[] answer = new String[3];
answer[0] = "stein";
answer[1] = "saks";
answer[2] = "papir";
JOptionPane.showOptionDialog(null, "choose answer", "player 1", 0, 0, null, answer, answer[0]);
JOptionPane.showMessageDialog(null, "player 1 has pressed " + (what should i put here???) );
}
答案 0 :(得分:1)
获取所选选项:
int choice = JOptionPane.showOptionDialog(null, "choose answer", "player 1", 0, 0, null, answer, answer[0]);