나는 TicTacToe 게임 '을 만들려고합니다. 사용자가 하나의 보드 만 재생할 수 있으며 사용자가 셀을 클릭하면 셀은 X/O로 채워지고 동일한 셀 (두 번째 보드의 임의의 지점에 있음)은 X/O로 채워집니다. 사용자는 두 보드 중 하나에서 이길 수 있습니다. 보드를 빌드하고 각각의 JPanel에 표시하려고 할 때 문제가 발생합니다. 이상적으로 JFrame을 전체 화면으로 설정하여 setSize (2000,2000)가되도록하십시오. JFrame이 튀어 나오고 두 TicTacToe 그리드가 함께 뭉개져 있지만 프로그램을 실행할 때. GridLayout 함께 JFrame/JPanel에 Squished
그래서 나는 팩을 (시도하는 것을 결정) 대신 : 상태 게임의 업데이트 (X의 차례, X 게임 등 원)도지기 것으로 보인다있을 해야하는 하단 부분 setSize(). 이상적으로 내가 원하는: 이상적으로이 내가 JFrame의 모습을 원하는 것입니다
: 좋은 소식은 게임 보드 unsquished 나타났다하지만 JFrame의이 굉장히 작았이다 JFrame을 전체 화면으로 만들지 만 setSize() 대신 pack()을 사용할 때 JFrame을 더 크게 만드는 해결책이 될 것입니다.
어떻게하면 전체 화면 JFrame에서 격자를 표시하지 않거나 pack()을 더 크게 만들 수 있습니까? 더 큰
public Attempt(){
JFrame frame = new JFrame("Shadow Tic Tac Toe Game");
frame.setSize(2000,2000);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
// Adds panel1 which will hold the first TicTacToe game.
panel1.setLayout(new GridLayout(3,3,0,0));
for(int d = 0; d < 3; d++){
for(int c = 0; c < 3; c++){
panel1.add(cell[d][c] = new Cell());
}
}
// Builds Panel2 which will hold the second TicTacToe game
panel2.setLayout(new GridLayout(3,3,0,0));
row = rand.nextInt(3);
column = rand.nextInt(3);
for(int n = 0; n < 3; n++){
panel2.add(cell[row][column] = new Cell());
}
// Adds Panel1 to the JFrame
frame.add(panel1, BorderLayout.EAST);
// Adds Panel2 to the JFrame
frame.add(panel2, BorderLayout.WEST);
// Updates the status of the game here (win/lose/draw/whose turn it is)
frame.add(jlblStatus, BorderLayout.SOUTH);
// Calls method Chose() which allows the player to chose which token they will play as
Chose();
frame.setVisible(true);
}