简体   繁体   中英

Why is my java code not working?

On the last JOptionPane, I'm trying to make the program return a dialogmessage that tells me what button the user pressed. How do I do this?

@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???)  );
    }

通过以下方式获取所选选项:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM