I'm developing Snake game using Java. Board's (where all action takes it place) width and height should be fixed (640 pixels * 480 pixels).
Structure:
In Main class I have something like...
setSize( 1024, 768 );
...and in Board class I have...
setSize( BOARDS_WIDTH, BOARDS_HEIGHT );
Problem is that main and only windows seems to be like 1024 * 768, but panel inside it - not like 640 * 480. I have setBackground() as well and background is filled more than 640 * 480.
Is there any way to make Board's width and height like 640 * 480, but main windows width and height - as much as Board's width and height are correct?
Right now it looks like this...
Edit:
All works... almost.
Main class:
add( new Board(), BorderLayout.CENTER );
pack();
setResizable( false );
setLocationRelativeTo( null );
setVisible( true );
setDefaultCloseOperation( EXIT_ON_CLOSE );
setTitle( "Snake (by daGrevis)" );
Board class:
setPreferredSize( new Dimension( 640, 480 ) );
Gray background is 642 * 482! Like there would be border that wraps all by 1 pixel!
Board.setPreferredSize(new Dimension(x, y));
.
.
//Main.add(Board, BorderLayout.CENTER);
Main.add(Board, BorderLayout.CENTER);
Main.setLocations(x, y);
Main.pack();
Main.setVisible(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With