简体   繁体   English

如何运行以“KeyEvent e”为参数的方法?

[英]How to run a method which has "KeyEvent e" as it's parameter?

Hi Devs I have a problem that how should I call it.嗨开发人员我有一个问题,我应该如何称呼它。 If I write "null" in the parenthesis, it gives error that e is null.如果我在括号中写“null”,则会给出错误 e 是 null。 My code is below for reference.我的代码如下供参考。

private void myMethod(KeyEvent e){
    if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
        System.exit(0);
    }else if(e.getKeyCode() == e.KeyEvent.VK_SPACE){
        label.setText("This is aa example");
    }
}

public static void main(String[] args){
    Main m = new Main();
    m.myMethod(??); //What should I enter in the parenthesis?
}

To work with actions or KeyEvents, you need to attach a Listener to a component.要使用操作或 KeyEvent,您需要将侦听器附加到组件。 you don't have a component that'll take one, and you don't have a Listener你没有一个可以接受的组件,你也没有一个 Listener

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 KeyEvent 上的 FXML Controller 中运行方法 - Run method in FXML Controller on KeyEvent 如何将具有多个覆盖作为参数的 valueOf 方法传递给方法 - How to pass valueOf method which has several overrides as parameter to method 按下 KeyEvent 时运行 JButton - Run the JButton when a KeyEvent has been pressed 如何在keyPressed(KeyEvent e)方法内部添加击键以更改球的颜色? 简单的KeyListener演示 - How do I add a keystroke inside of keyPressed(KeyEvent e) method to change color of ball? simple KeyListener demo 以 class 作为参数,其中有一个特定的方法 - Take a class as a parameter which has a particular method in it 如何序列化 object 它的方法有多个参数 - How to serialize an object which it's method has multiple parameters 如何从keyevent方法调用文本字段变量? - How to call on a textfield variable from a keyevent method? 是否有任何有效的方法来保持一个线程,它在其运行方法中有ActionListener,直到发生点击事件为止? - Is there any efficient way to keep a thread, which has ActionListener in it's run method, alive until a click event has occured? 如何实现具有通用返回类型和通用参数的通用方法? - How can I implement generic method which has generic return type and generic parameter? 如何存储从以数组为参数且返回类型为double的方法传递的值? - How to store a value, passed from a method which has an array as parameter and return type of double?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM