【问题标题】:"Not applicable for the arguments (void)" error when using EventQueue.push() method in Java在 Java 中使用 EventQueue.push() 方法时出现“不适用于参数 (void)”错误
【发布时间】:2015-03-05 17:35:35
【问题描述】:

我有一个使用 EventQueue.invokeLater() 的游戏。我正在添加代码,当游戏结束时我想推送一个新的 EventQueue 有效地重新启动游戏,但是我在 Eclipse 中收到一个错误,上面写着“EventQueue 类型中的方法 push(EventQueue) 不适用于参数(空白)”。我是使用 EventQueue 类的新手,所以可能有一些我不理解的简单内容,或者我试图错误地使用 EventQueue。这是我第一次使用 EventQueue.invokeLater() 运行程序的代码。

public class App extends JFrame{
    public static int level;
    public App(){
        add(new GameBoard());   
        setResizable(false);
        pack();
        setTitle("Planetary Resources Game");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
    }   
    public static void main(String drew[]){ 
        MyQue r = new MyQue();
        EventQueue.invokeLater(r);      
    }
}

这是我想使用 Event.Queue.push() 方法重新启动游戏的代码。

if(GameLogic.game_is_over == true){
                MyQue r = new MyQue();
                EventQueue.push(EventQueue.invokeLater(r));
                MineCalculation.rocketfuel_amount= 100;
                GameLogic.game_is_over = false; 
            }

谢谢大家的帮助

【问题讨论】:

  • 这种方法行不通;取而代之的是reset()游戏的模型,如图here

标签: java swing jpanel eventqueue


【解决方案1】:

这是因为push 接受EventQueue 类型的参数,但您使用EventQueue.invokeLater() 的结果调用它,这是一个void 方法。

【讨论】:

    【解决方案2】:

    EventQueue.invokeLater(r) 是一个void,您不能将它用作push 方法的参数。

    【讨论】:

    • 是否可以使用 push() 重启游戏
    • 阅读文档:Replaces the existing EventQueue with the specified one. Any pending events are transferred to the new EventQueue for processing by it.
    猜你喜欢
    • 2013-12-25
    • 2018-07-19
    • 2015-12-20
    • 1970-01-01
    • 2019-04-04
    • 2020-06-05
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    相关资源
    最近更新 更多