Using custom JOptionPane buttons? int delayed error?

Sorry if this sounds like a dumb question, but I searched everywhere on custom buttons in JOptionPane. I came across how to create special buttons, but I can not use it in my program.

int choice; Object[] doors = { "Door 1", "Door 2", "Door 3" }; JFrame frame = new JFrame(); input = "Which door do you choose?"; choice = JOptionPane.showOptionDialog(frame, input, "Doors", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, doors, doors[2]); if (car == 1 && choice.equals(doors[0])) { open = 3; option = 2; } if (car == 1 && choice.equals(doors[1])) { open = 3; option = 1; } if (car == 1 && choice.equals(doors[2])) { open = 2; option = 1; } if (car == 2 && choice.equals(doors[0])) { open = 3; option = 2; } if (car == 2 && choice.equals(doors[1])) { open = 1; option = 3; } if (car == 2 && choice.equals(doors[2])) { open = 1; option = 2; } if (car == 3 && choice.equals(doors[0])) { open = 2; option = 3; } if (car == 3 && choice.equals(doors[1])) { open = 1; option = 3; } if (car == 3 && choice.equals(doors[2])) { open = 2; option = 1; } 

Note. This is not my whole program, but only a problematic aspect.

The parameters in the dialog box are displayed perfectly, only there is an error that says that "int cannot be delayed." I think I used an erroneous comparison, but how can I fix this?

+4
source share
1 answer

You are trying to dereference an int that you are trying to call a method by int, by choice, and you just can't do it using Java. Why not just use the selection in your door grill? doors[choice] ?

 // first check that the JOptionPane wasn't closed by the user if (choice != JOptionPane.CLOSED_OPTION) { String chosenDoor = doors[choice]; } 

Or choosing a test, as you are testing a car using it as a number as an int.

+6
source

Source: https://habr.com/ru/post/1439920/


All Articles