Skip to content
Advertisement

Is there a faster way to create 12 buttons?

I am doing a task where I need to create a 3×4 GridLayout with 12 buttons. The task is when I click any of the buttons, all other buttons change the value to 1. Now, this is how I did it:

JavaScript

My question is – is there a faster way to do this than just copying the same lines 12 times? I am fairly new at programming in Java, so any insight would be helpful, thank you!

Advertisement

Answer

Putting your buttons in an array can help a lot

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement