473,672 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get KeyListener to work

42 New Member
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 (setBattleContr oller 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 3427
Humakt
42 New Member
Any help? It doesn't just seem to do anything.
Jul 23 '09 #2
r035198x
13,262 MVP
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 New Member
@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
1578
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 be done, and I'm ignorant of why b) there is a workaround and/or i'm doing this the wrong way Hopefully someone can enlighten me?
22
2544
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 the video from a DVD but not the audio. He had been searching for an answer for days on support.microsoft.com but found none. I suggested Google and Gateway. Gateway had nothing, but sure enough, search for *XP DVD no sound* on Google and...
119
4579
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, http://www.alistapart.com/articles/betterliving/ I read on http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dnnetdep/html/netfxcompat.asp It said they changed stuff like this
1
5523
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 table of the MS-SQL Database, "TestODBC". I wanted to use StoredProcedure1 as the bound recordsource for a new form Form1. But I
9
2380
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 any of the response.write lines from inside the sub. ******************************************* <%@ Application Language="VB" %> <script runat="server">
15
4036
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 CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
6
4868
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
2819
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 tried several solution but none have worked. Heres the code public class Test extends Canvas implements KeyListener { static final int WIDTH =700; static final int HEIGHT =700; static final String TITLE ...
9
14350
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 being pushed to invoke different commands and methods, but apparently KeyListener doesn't work inside of a loop. Is there another, relatively simple way for me to read keyboard input?
0
8485
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8403
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.