Java 关闭另一个JFrame后,如何打开新的JFrame并运行游戏?
我正在制作一个扫雷游戏,我希望用户能够在玩游戏之前从初学者、中级和高级中进行选择。到目前为止,我有一个JFrame,当我打开程序时,它会打开,每个困难都有按钮 下面是我的主要函数和选择函数的难度。我想知道在调用choosegameedefestion之后,我怎么还能调用main函数中的所有函数,因为现在它们没有被调用Java 关闭另一个JFrame后,如何打开新的JFrame并运行游戏?,java,jframe,minesweeper,Java,Jframe,Minesweeper,我正在制作一个扫雷游戏,我希望用户能够在玩游戏之前从初学者、中级和高级中进行选择。到目前为止,我有一个JFrame,当我打开程序时,它会打开,每个困难都有按钮 下面是我的主要函数和选择函数的难度。我想知道在调用choosegameedefestion之后,我怎么还能调用main函数中的所有函数,因为现在它们没有被调用 public static void main(String[] args) { chooseGameDifficulty(); game.initGame();
public static void main(String[] args) {
chooseGameDifficulty();
game.initGame();
initBoard();
getClick();
while (gameOver == false) {
showUserTile();
checkGameWon();
}
}
public static void chooseGameDifficulty() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame chooseDifficulty = new JFrame("Minesweeper");
chooseDifficulty.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
chooseDifficulty.setPreferredSize(new Dimension(500,500));
chooseDifficulty.setLayout(new GridLayout(1, 3));
JButton B = new JButton("Beginner");
JButton I = new JButton("Intermediate");
JButton E = new JButton("Expert");
chooseDifficulty.add(B);
chooseDifficulty.add(I);
chooseDifficulty.add(E);
B.addMouseListener(
new MouseListener() {
public void mouseClicked(MouseEvent event) {
game.setGameDifficulty("Beginner");
chooseDifficulty.setVisible(false);
}
public void mouseExited(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
}
public void mousePressed(MouseEvent event) {
}
}
);
// same thing for the other buttons
chooseDifficulty.pack();
chooseDifficulty.setLocationRelativeTo(null);
chooseDifficulty.setVisible(true);
}
这里有一种安排Swing组件和模型/视图/控制器类的方法。