Java game - layout -
i'm making tetris in java , have few questions layout in reference picture below:
should gameboard , scoreboard separated 2 jpanels within 1 jframe... set jframe size equal gameboard + scoreboard?
jframe f = new jframe("tetris"); f.setsize(gameboard.getwidth()+scoreboard.getwidth(), gameboard.getheight());
or should 1 jpanel within 1 jframe contains everything...? (here set frame equal size of gameboard + 200 on right have space show buttons, score, next piece, etc...) if so, how align buttons , such?
jframe f = new jframe("tetris"); f.setsize(gameboard.getwidth()+200, gameboard.getheight());
any thoughts on how should lay out game?
don't use
setsize
. use layout, position components, , callf.pack
. automatically size window correctly.you should have more 1
jpanel
. two-panel layout looks good.
for example:
jpanel contentpane = new jpanel(new borderlayout()); contentpane.add(maingamepanel, borderlayout.center); contentpane.add(scorepanel, borderlayout.east); f.setcontentpane(contentpane); f.pack();
see using layout managers more information.
Comments
Post a Comment