I’m making a simple rock, paper scissor game in Java, and I have two JLists where Player 1 and Player 2 can make their selection. The thing is, I want the JList to be hidden when a selection is made (for obvious reasons, otherwise there’d be no point with the game ^_^), but I havent found a way to do this and still keep the selected value. Can anyone point me in the right direction?
Thanks!
JList extends JComponent, which has an extensive list of methods you could use to varying degrees. For example, if you just want to disable the JList from user interaction, there is setEnabled which will “grey” out that component. If you want to hide the JList completely, see setVisible.
Whichever route you take, just drop one of these methods in where your user makes their selection, and you should be good to go. In order to store the user’s selection, you’ll want to save that to a variable that goes beyond that particular JList so you can later compare it with the opponent’s value. I’d recommend giving this a read.