Java Grid with button + id to each button [closed]

2019-09-16 19:41发布

I'd like to make a grid in a JPanel full of buttons, then i want to create them in a loop because i've aproximatly 100 buttons. Each button created must have an id differents see my picture to understand better :s

I think I have to create a method like this but I don't know how to proceed :

public Button(String text , int id){
     //code 
}

And then add it to a loop to create the grid :)

enter image description here

if anyone can help me it would be very appreciated ! ;)

1条回答
Lonely孤独者°
2楼-- · 2019-09-16 19:47

Each GridButton "knows its location on the grid." The complete example shows how to create the buttons in a loop and how to calculate grid coordinates in a List<GridButton>.

image

查看更多
登录 后发表回答