public ArrayList createAPileOfDisks() {
// Get the array number of disks from the user
Input in = new Input();
int n;
do {
n = in.readIntDialog("Enter the number of disks "
+ "(between 1 and " + MAXIMUM_NUMBER_OF_DISKS + ")");
if (n <= 0 || n > MAXIMUM_NUMBER_OF_DISKS) {
// display an error message
JOptionPane.showMessageDialog(null, "Invalid input",
"Input Error", JOptionPane.WARNING_MESSAGE);
}
} while (n <= 0 || n > MAXIMUM_NUMBER_OF_DISKS);
// Create the list of disks
ArrayList<Oval> list = new ArrayList<Oval>(n);
int chgSize = HEIGHT;
for (int i = 1; i <= n; i++) {
// Find the center of the window
int centerX = (int) (WIDTH / 2) - (chgSize / 2);
int centerY = (int) (HEIGHT / 2) - (chgSize / 2);
// Draw an Oval
Oval o = new Oval(centerX, centerY, chgSize, chgSize,
randomColors(), true);
list.add(o);
chgSize -= WIDTH / n;
}
return list;
}
public Color randomColors() {
Color c = new Color((int) (Math.random() * 256),
((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
return c;
}