Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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. 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?
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To work with actions or KeyEvents, you need to attach a Listener to a component. you don’t have a component that’ll take one, and you don’t have a Listener

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading