Hi. I am coding a game for my basic Java programming course, and I am currently coding a game (Othello, aka Reversi).
I am having issues with the JButton size.
public void game ()
{
resize (800, 680);
game = new Panel ();
Panel board = new Panel (new GridLayout (row, col, 0, 0));
//board.setSize (new Dimension (640, 640));
//initialize tracking array to have all black backgrounds
tracker = new Color [row] [col];
for (int i = 0 ; i < row ; i++)
{
for (int j = 0 ; j < col ; j++)
{
tracker [i] [j] = Color.black;
}
}
[B]//declare a new array of buttons
a = new JButton [total]; //<--resize the button (I think this is the one)
//a.setSize (85, 85); //Attempt
//initialize each of the buttons in the array
//with an empty label
for (int i = 0 ; i < total ; i++)
{
a [i] = new JButton (createImageIcon ("images\\blank.gif")); \\Calling blank image file, 80x80
a [i].addActionListener (this);
a [i].setActionCommand ("" + i);
a [i].setBackground (Color.black);
board.add (a [i]);
}
[/B]
game.setBackground (Color.black);
//Adding
JPanel grid = new JPanel ();
//Creating the layout
grid.setLayout (new BoxLayout (grid, BoxLayout.Y_AXIS));
grid.setBackground (Color.black);
grid.add (menuBar);
grid.add (board);
game.add (grid);
screens.add ("3", game);
}
This is one of the cards (screens), and the layout used for that is CardLayout. I resized the window to 800 by 680.
And then I copied the teacher's 2D button array code, and changed it slightly. I just made it so that every button appears to be blank. The middle four are different (for the start of the game, but I don't know how to fix it yet).
I need to resize the button to 80x80 (the image is exactly 80x80, square). So the square grid can be 640x640 (or maybe slightly bigger if necessary).
It might also be worth noting that I am using Java 1.4.2, Ready to Program v1.7.1
Thank you