Vanavah Edwards
asked on
Error with KeyPress Events
I am testing for the enter keypress in a JformatedField date. I want when the user press enter on this date field "sodate" it calls a calendar - CalendarTyp2(). However, I am getting an error on "KeyEvents" in the line - public static class KeyEvents implements KeyListener. Can you help me to resolve this error as to what I could be doing wrong? For further analogy, I delared the method as KeyEvents ke = new KeyEvents(); and add the component as sodate.addKeyListener(ke)
public static class KeyEvents implements KeyListener {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==10) {
new CalendarType2();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>For further analogy, I delared the method as KeyEvents ke = new KeyEvents();
Not understandable what the above line means,
but th eerror becasue you need to impleemnt all methods
There may be, but no sense remebering it - it is simpler to paste the methods in your code
ASKER
YOu are right it works. Thank you. Thank you very much. I will now close this session.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
One more thing, must this procedure be done for other listener events.
Each listener interfcae has its own set of methods.
Say, ActionListener has just one method actionPerformed you'll normally implement it
But those which have sveeral methods - all need to be implemented - like KeyListener, MouseListener
But your IDE usually will remind you which method is missing - you hoever over red line on your mistake-
it will give you method name to implemnet, then if still red hover again, etc.
until you have all methods implemented, _MouseListnere has 5 of them
Say, ActionListener has just one method actionPerformed you'll normally implement it
But those which have sveeral methods - all need to be implemented - like KeyListener, MouseListener
But your IDE usually will remind you which method is missing - you hoever over red line on your mistake-
it will give you method name to implemnet, then if still red hover again, etc.
until you have all methods implemented, _MouseListnere has 5 of them
ASKER
Thank you very much again.
You are always welcome.
ASKER