当按下相应的键时,这段代码调用两个单独的游戏。窗口出现,但用户无法玩游戏。屏幕没有响应。我该如何解决这个问题?
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_1)
{
//calls tic tac toe game, and point counter
TicTacToe tic = new TicTacToe();
TicTacToeDriver.main(null);
PointCounter();
}
else if(e.getKeyCode() == KeyEvent.VK_2)
{
//calls hanman game, and point counter
Hangman hang = new Hangman();
HangmanDriver.main(null);
PointCounter();
}
}
答案 0 :(得分:0)
我认为,更容易做到你想做的事就是:
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_1) {
//calls tic tac toe game, and point counter
TicTacToeDriver.main(args);
PointCounter();
}
else if(e.getKeyCode() == KeyEvent.VK_2) {
//calls hanman game, and point counter
HangmanDriver.main(args);
PointCounter();
}
}
如果有效,请告诉我。