473,387 Members | 1,650 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,387 software developers and data experts.

Can't get KeyListener to work

42
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 object):

Expand|Select|Wrap|Line Numbers
  1. public void setBattleController(Battle b){
  2.         this.addKeyListener(b);
  3.         this.setFocusable(true);
  4.         this.requestFocus();
  5.     }
  6.     public void removeBattleController(Battle b){
  7.         this.removeKeyListener(b);
  8.     }
Battle (there is another controller for view, but it doesn't use keylistener)

Expand|Select|Wrap|Line Numbers
  1. public void keyTyped(KeyEvent ke){
  2.                //bunch of code
  3.         System.out.println("Here we are");
  4. }
Jul 23 '09 #1
3 3418
Humakt
42
Any help? It doesn't just seem to do anything.
Jul 23 '09 #2
r035198x
13,262 8TB
Put the println before the bunch of code to see if listener is called at all.
You might have have to give more information.
Jul 24 '09 #3
Humakt
42
@r035198x
I got it to work after regenerating serialUIDs for both classes, though I'm not yet finished with code. I'm bit confused why my middlemouse-button is not working with my current program in current system as it did with my laptop.

Any ways to get focus on JPanel for getting keyevents? (Without using mouselistener for focusing)
Jul 24 '09 #4

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

Similar topics

3
by: Jonah | last post by:
Hi I've run some tests and I have to conclude that mysql and fopen doesn't work when you call it in this way. I don't understand why, it's got to be either one of 2 things: a) this just can't...
22
by: The Road To Utopia | last post by:
Here's one for the trolls...a common jibe from them is setting up audio/video hardware under linux. Ok, true story: at work today, someone asked me if I could tell him why his XP Home would play...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
1
by: Lyle Fairfield | last post by:
I created a new MS-SQL Database, "TestODBC". I made Table1 and StoredProcedure1. I made an ODBC DSN for that MS-SQL Database. I created a new AccessXP mdb, "TestODBC". I linked to the...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.