Link to home
Start Free TrialLog in
Avatar of Vanavah Edwards
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();
			 }
		}
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vanavah Edwards
Vanavah Edwards

ASKER

Okay I will do.  However, I is there a key adapter that can be use where you only need one but all methods would be accessible.

 >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
YOu are right it works.  Thank you.  Thank you  very much.  I will now close this session.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thank you very much again.
You are always welcome.