Problems with GUI GridLayout and Panels in Frames
Posted on 2003-02-20
I'm practicing Java by working on programming "Connect 4" the board game. Here's some info about the structure of it. The application object Connect4 extends Frame and uses the default FlowLayout. A Gameboard extends Panel, uses a GridLayout, and is a member of Connect4. The Gameboard has a Canvas object for each grid element, which is used to paint the gamepieces.
Problem: When the frame is resized the grid elements resize themselves as well.
Q: Is it possible to make the grid a fixed size, regardless of the size of the Frame? I would like to have the elements on the grid stay a constant size if possible, rather than grow and shrink with the Frame. Any suggestions?
Problem: I wanted to add a TextArea as a status window for the players onto the "Connect 4" Frame. I instantiated a Panel and TextArea then added it to the Frame.
// Gameboard has been added to "this" Frame already
ta = new TextArea( "Status", 2, 30 );
p = new Panel();
p.add( ta );
// add status panel to the "Connect4" Frame
this.add( p );
This seems to coverup the Gameboard, instead of being placed next to, or below it in the Connect 4 Frame. I expected both the Status Panel and Gameboard Panel to be displayed.
Q. How come both the Gameboard Panel and the Status Panel are NOT displayed in the Frame? The only this showing is the Status Panel. Any suggestions?