public game()
{
setTitle("game");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLayout(new BorderLayout());
buildMenu();
setJMenuBar(menuBar);
buildGreetingsPanel();
add(greetingsPanel, BorderLayout.NORTH);
buildGamePanel();
add(gamePanel, BorderLayout.CENTER);
buildStatusPanel();
add(statusPanel, BorderLayout.SOUTH);
buildSettingsPanel();
add(settingsPanel);
pack();
setVisible(true);
}
[...............]
private void buildGamePanel()
{
gamePanel = new JPanel();
gamePanel.setBorder(BorderFactory.createLineBorder(difficultyColor));
gamePanel.setPreferredSize(new Dimension(9 * span, 9 * span));
gamePanel.setLayout(new GridLayout(40, 40, 0, 0));
for(col = 0; col < gameWidth; col++)
{
for(row = 0; row < gameHeight; row++)
{
buttons[col][row] = new JButton();
buttons[col][row].setBounds(4, 4, span, span);
buttons[col][row].addMouseListener(new mouseListener());
gamePanel.add(buttons[col][row]);
}
}
}
正如标题所示
我添加了buildGamePanel();
和add(gamePanel, BorderLayout.CENTER);
已经。有什么问题?感谢
编辑:由于没有人回答,问题可能在其他地方。 我添加了公共游戏();构造函数可能是错误的来源。
答案 0 :(得分:0)
问题在于BorderLayout();
编译时,在gamePanel之前将settingsPanel添加到GUI的中心。 忘了指定它应该放置如下:
add(settingsPanel, BorderLayout.EAST);