0
當我運行這段代碼,該按鈕顯示了在JPanel的,但一旦我按一下按鈕,沒有任何反應。任何關於我要去哪裏的錯誤建議?很抱歉,如果它真的很簡單。談到圖形用戶界面,我相當新。的JButton後的JPanel JTable中放置按下
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);
}
});