有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何关闭打开另一个框架的JFrame?

我有一个以welcomeScreen JFrame开始的程序,它有一个JButton,可以选择启动游戏。。当我点击该按钮时,它会打开游戏的JFrame,但不会关闭。。怎么做呢?我只知道这个系统。退出(0),这将关闭所有


共 (2) 个答案

  1. # 1 楼答案

    你可以试试:jFrame.dispose();

  2. # 2 楼答案

    I've a program that starts with a welcomeScreen JFrame, on which it has a JButton with the option of starting the game.. when I click that button, it opens the JFrame with my game however it does not close.. anyway of how to do this? I only know System.exit(0) and this closes everything..

    • 不要创建另一个JFrame

    • 在切换卡后,将CardLayoutJFrame.pack()一起使用