I'm designing a program to draw random boxes inside a JPanel, is there a way to declare an integers max value? The program says it must be a random height and width but I must remain inside the confines of the JPanel.
Asked
Active
Viewed 1,646 times
1 Answers
0
Integer.MAX_VALUE
Unless of course you're trying to set a custom max value. Then you would need to read the Random documentation to do something like this.
public class TestingStuff {
public final int MAX;
TestingStuff() {
Random r = new Random();
MAX = r.nextInt(Math.abs(r.nextInt()));
System.out.println(MAX);
}
public static void main(String args[]) {
TestingStuff t = new TestingStuff();
}
}
While creating this I had issues declaring MAX as static and initializing it. It would seem that you can either make it static or final.

Jared Beekman
- 320
- 2
- 10