[英]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.