StackOverFlow Question
Hello for the second time today dedicated stack overflow users! XD
So I'm trying to set the positioning of these 9 buttons in a grid format with .setBounds which accepts (xCoordinate, yCoordinate, #ofPixelsWide, #ofPixelsTall)
Would anyone know of an even more efficient/compact way to do this? I would like to know even if it doesn't use .setBounds, after all I'm here to learn XD
Thanks for any suggestions
for (int i = 0; i < groupOfButtons.length; i++) {
int x = 0, y = 0;
if (i == 1 || i == 4 || i == 7) {
x = 110;
}
if (i == 2 || i == 5 || i == 8) {
x= 220;
}
if (i > 2 && i < 6) {
y = 110;
}
if (i > 5 && i < 9) {
y = 220;
}
groupOfButtons[i].setBounds(x, y, 100, 100);
}
This was instead of writing this btw (this way is actually shorter but looks a lot more messy):
groupOfButtons[0].setBounds(0, 0, 100, 100);
groupOfButtons[1].setBounds(110, 0, 100, 100);
groupOfButtons[2].setBounds(220, 0, 100, 100);
groupOfButtons[3].setBounds(0, 110, 100, 100);
groupOfButtons[4].setBounds(110, 110, 100, 100);
groupOfButtons[5].setBounds(220, 110, 100, 100);
groupOfButtons[6].setBounds(0, 220, 100, 100);
groupOfButtons[7].setBounds(110, 220, 100, 100);
groupOfButtons[8].setBounds(220, 220, 100, 100);