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

Vanavah EdwardsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:


You need to implement not just one but all methods of KeyListner

Thats why the error om implements KeyListener line
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:

 public void keyPressed(KeyEvent e) {
// something here
}

public void keyTyped(KeyEvent e) {
// maybe nothing here but themethods needs to be
}


public void keyReleased(KeyEvent e) {
// maybe nothing here but themethods needs to be
}
0
Vanavah EdwardsAuthor Commented:
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.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

for_yanCommented:

 >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
0
for_yanCommented:
There may be, but no sense remebering it - it is simpler to paste the methods in your code
0
Vanavah EdwardsAuthor Commented:
YOu are right it works.  Thank you.  Thank you  very much.  I will now close this session.
0
for_yanCommented:
0
Vanavah EdwardsAuthor Commented:
One more thing, must this procedure be done for other listener events.
0
for_yanCommented:
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
0
Vanavah EdwardsAuthor Commented:
Thank you very much again.
0
for_yanCommented:
You are always welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.