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

♀尐吖头ヾ 提交于 2019-12-12 01:14:00

问题


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 :)

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


回答1:


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>.



来源:https://stackoverflow.com/questions/21073313/java-grid-with-button-id-to-each-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!