Reputation: 11
I'm making a game where the player has to click circles(buttons) which spawn randomly on the screen and disappear after some time. If the player misses them, he loses points, and if he hits them he gains points.
Would really appreciate anyone showing me an example of randomising the location of a button in absolute layout and/or grid bag layout.
Upvotes: 1
Views: 226
Reputation: 31
I think NullLayout would be a good idea - http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html
If you want to do it with GridBagLayout you can find an answer here Layout to represent dynamic dashboard with GridBagLayout.
You have to create a grid filled with dummy panels and then replace the dummy panels with your buttons.
c.gridx = (int)(Math.random()*NumOfGBLColumns);
c.gridy = (int)(Math.random()*NumOfGBLRows);
Upvotes: 1