Is there any way to assign random numbers to JButtons? I'm creating a game where the player must click the draw button to shuffle the numbers on the cards. I want the numbers to be 1, 2, 3, 4, 5, 6, 7, 8, and 9.
How do I do this?
Is there any way to assign random numbers to JButtons? I'm creating a game where the player must click the draw button to shuffle the numbers on the cards. I want the numbers to be 1, 2, 3, 4, 5, 6, 7, 8, and 9.
How do I do this?
Random r = new Random();
r.nextInt(max - min + 1) + min
This will generate random numbers for you within bounds (inclusive). So, your min is 1 and max is 9.
to set text on JButton there is a method available (https://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setText(java.lang.String))