473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Unable to implement KeyListener

Hi all,

firstly please advise if I've posted incorrectly as this is my first post.

Consider the following files :

Grandparent - public class

Parent - public abstract class extends Grandparent

Child - public abstract class extends Parent


I cannot change the class type or extensions in these files as these are a structure I did not create.

My issue is I am trying to create a KeyListener in a subclass of Child - I'll call Egg:

import java.awt.event.KeyListener

Egg public class extends Child implements KeyListener

I have tried various ways of achieving this:

- addKeyListener(keyListener)

- KeyListener listener = new KeyListener()

but end up with a "symbol not found ....KeyListener" when compiling.

I can create a working key listener in it's own separate file, I just can't seem to get it into this structure.

Any suggestions ?

And as I said please point out if I am posting incorrectly.

Thank you.
Apr 8 '11 #1

✓ answered by sanat

as Egg implements the KeyListener it can handle the KeyEvents.

So the following code should do the task:

addKeyListener(new Egg());

NOTE : if the component to which you want to make key event sensitive is there in the Egg class then write :
addKeyListener(this);

Pls ask if u ve any doubt......

2 2422
sanat
5
as Egg implements the KeyListener it can handle the KeyEvents.

So the following code should do the task:

addKeyListener(new Egg());

NOTE : if the component to which you want to make key event sensitive is there in the Egg class then write :
addKeyListener(this);

Pls ask if u ve any doubt......
Apr 14 '11 #2
Thanks sanat this cleared it up for me, all working now.
Apr 22 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Oplec | last post by:
Hi, I am learning standard C++ as a hobby. The C++ Programming Language : Special Edition has been the principal source for my information. I read the entirety of the book and concluded that I...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
7
by: sunny | last post by:
Hai, can anyone implemen this problem.I am unable to implement.i tried but i am going out of the design pattern. Implement the Factory Design Pattern for the following scenario: Base class =...
4
by: MikeofPet | last post by:
I am trying to implement FTP in a PHP script but am unable to make the connection to the remote server. The connection step times out at the fsockopen function. I am not sure if it is relevant but...
4
by: pankajs | last post by:
Hello freinds! I am developing a game & a problem occur with pressing the keys the class name is game it extends JPanel, when I register keylistener by writing addKeyListener(this); in the...
1
twitch3729
by: twitch3729 | last post by:
Basicaly, I have a frame with only a Canvas on it and a KeyListener. For some reason the keyListener stops registering my keys as soon as I have moved the Window from its starting position. I have...
3
by: Girish | last post by:
I have two application running in one server, both have same sqlserver connection strings in their web.config files. i want to combine both connection strings in one config file. please suggest...
9
by: zakwiz | last post by:
I am relatively new to Java, so please excuse me if I'm not specific enough. I am making a program where a large portion of it is just one big while loop, and I want to be able to read specific keys...
3
by: Humakt | last post by:
I've done KeyListener before successfully, but for some reason I can't get it to work in my recent project. Here is the code: View class (setBattleController is called upon creating new Battle...
2
mrjohn
by: mrjohn | last post by:
Hey, I'm trying to make a program that will recognize when certain keys are released, so that I can encorperate it into a game I'm making. Unfortunately, it doesn't seem to be working. When I run the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.