为什么我的java代码不起作用?

时间:2015-10-23 18:49:31

标签: java

在最后一个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???)  );
    }

1 个答案:

答案 0 :(得分:1)

获取所选选项:

int choice = JOptionPane.showOptionDialog(null, "choose answer", "player 1", 0, 0, null, answer, answer[0]);