I don't know how to lay out a screen in Java
I am creati开发者_开发知识库ng a game using java, and I'm not quite understanding how to lay out buttons in windows.
I wants seven columns of buttons, 10 high. Each button showing a single digit number, or grayed out. jbutton buttons[] 0-70
To the right, three squares that can show a red X (strikes) that remain visable while empty. I also need a 'Go' button and a 'Clear' button. I was thinking about the strikes in a horizontal arrangement, but very flexable on final design.
The only things defigned are the jbuttons that will hold the numbers, the rest can be built upon any advice received here.
I'm not just looking for an answer, I want to understand how it came to be. PLEASE OVERexplain how.
The Java tutorials have a very thorough chapter on layout managers. Read through it. ANd keep in mind: layout managers are meant to be combined.
For your 7x10 buttons, you definitely want to use a GridLayout
. For the overall layout, you could use a BorderLayout
with the grid taking up its center spaces, and the other control could go in its other spaces.
I assume you're using Swing, in which case take a look at this GridBagLayout tutorial.
Use Layout Managers. Make multiple JPanels and set an appropriate manager for each. Sounds like you need a GridLayout.
精彩评论