当我运行此代码时,该按钮会显示在 JPanel 上,但是一旦我单击该按钮,则什么也没有发生。关于我在哪里出错的任何建议?对不起,如果它真的很简单。说到 GUI,我还是个新手。
final JPanel card3 = new JPanel();
//Tetris setup
JButton startGame = new JButton("START GAME");
card3.setLayout(new GridBagLayout());
GridBagConstraints gbc2 = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(2,2,2,2);
card3.add(startGame, gbc2);
gbc.gridy = 1;
startGame.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Tetris game = new Tetris();
JTable table = new JTable(game.getNumRows(), game.getNumCols());
card3.add(table);
}
});