Weird keylistener problem...

Advertisement
I just upgraded my java to 1.4.2 which caused this problem i believe. I add an action listener with the following code:
    this.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        main_keyPressed(e);
    });This worked fine in an older version of java, but in 1.4.2 it doesnt get my keyinput from the frame. 'this' refers to my class that extends JFrame... Im not sure what is wrong... maybe I added it to the wrong object even though it worked fine with another version of java.
Thanks for your help,
CoW
Advertisement

Replay

If a control on the JFrame has the focus it needs to have the KeyListener, as in the appended code. In this case the JFrame passes the KeyStokes off to the JTextArea before the JFrame KeyListener sees them. Change the ta to this on line 14 and you will see no more KeyEvents.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class TestKey extends JFrame
     Container cp;
     JTextArea ta;
     TestKey()
          cp = getContentPane();
         ta = new JTextArea(20,80);
          ta.addKeyListener(new java.awt.event.KeyAdapter()
                public void keyPressed(KeyEvent e)
                     main_keyPressed(e);
          cp.add(ta,BorderLayout.CENTER);
          pack();
     void main_keyPressed(KeyEvent e)
          System.out.println(e);
     static public void main(String[] args)
          TestKey tk;
          tk = new TestKey();
          tk.show();

Related Topics

  • KT6V Weird boot problems

    Hi.. I'm having this weird boot problem (and no it doesn't seem to be the standard one) OK.. I have the following : AMD Athlon 2000+ KT6V LSR mainboard 2x 256 Crucial PC2700 memory IDE Hard Disk (120gb segate) Creative 5700ultra Graphics card (AGP) C

  • N82 v 20.0.062 RM-313 WEIRD BROWSER PROBLEMS WITH ...

    Watching videos on youtube via standard built-in nokia browser worked flawlessly on my nokia N82 black. Right out of the box I could watch standard desktop version of youtube webpage and play any video BUT ... suddenly (and I have no idea what has ca

  • Weird Date Problem in SQL Query

    Dear Members, Iam using the following query: SQL>select api.attribute2 PO_NO, substr(api.attribute4, 10, 5) REL_NO, api.invoice_num, SUM(T.ACCOUNTED_DR) DR, SUM(T.ACCOUNTED_CR) CR from gl.gl_je_lines t, GL_CODE_COMBINATIONS GCC, ap_invoices_all api W

  • Weird audio problem in Soundtrack

    Ok, first of all, I'm sorry about my english, this is a tricky thing and I'm not sure of making myself clear. If I'm not please tell me and I try to mess it up a little more... We film short movies without problem until now. We shoot the video (Sony

  • N91 weird WLAN problem

    Hi, Good day to you all! I have a weird problem with my N91's WLAN, when it is in phone mode (general mode) I can't detect any access point or wifi hotspot on "connection manager>available WLAN" menu, even I'm just beside my wireless router,

  • Weird touch problem in video

    In the past few days I have noticed a VERY weird problem -- when in video mode and only in LANDSCAPE, it will only register touches every once in a while. In portrait mode it's fine. And this is only the video app -- nothing else does this. Not even

  • KeyListener problems

    I'm making a simple Packman game as an Applet. To control the my pacmans I would like to use the keybord, but I'm having trouble getting my events through to the right receiver. The trouble is I'm not sending my events to a component in the applet cl

  • Weird printer problem using Express, Vista and Dell

    I have a new Dell Inspiron 1525 running Vista Home Premium. I have a Brother printer hooked up to my Express. Set up printer via Bonjour w/o problems. Computer recognizes the printer and seems to send info to it. But when I try to print, it only prin

  • Really weird network problem... Please help!

    This is really starting to tick me off, so I hope you can help me. This isn't exactly Archlinux related, but the problem persists on the whole network regardless of OS being used. Ok, so I got my new D-Link 5-port switch home a few days ago. I wanted

  • Weird Dock problem

    I know this might be better posted under OS X but since it only happens on my laptop I thought I'd post it here. What happens is I will go to the Dock to open or switch to an application, and nothing happens. (This is after a good amount of time when

  • Weird syncing problem

    In iTunes, various songs show up with an exclamation mark. When I try to play them, a dialogue says they cannot be used because the original file cannot be found. It asks me if I would like to locate them, which is pointless, because countless attemp

  • Weird iTunes Problem with Podcast

    I have been stumped on this for several months now. My Escape Adulthood podcast has been listed in iTunes for a while now. I have three done episodes. Unfortunately, anytime anyone tries to download or preview episode #2 or #3 from iTunes, all they g

  • Weird Compilation Problem??

    Hi there! I'm having some problems with my Girlfriends 30g iPod Video. Basically, I have a 60g iPod Video and whenever I import a compilation onto my iPod it comes up in the Compilations tab, like it's supposed to, which is ace, becasue then i can br

  • Weird Viewing Problem

    I imported about 60 pictures from my camera last night onto iPhoto (camera is a Nikon Coolpix S7c). All went fine, all imported with no problem. However, some of the photos cannot be viewed. Thumbnails are fine, but when I click on the thumbnail, the

  • Really weird keyboard problem with my macbook.

    Hi Everyone, I've been having an unexplainable keyboard problem all day now. The keyboard on my Macbook is unresponsive, and the trackpad is stuck on right click. BUT when I plug in a USB keyboard, both my macbook keyboard and my trackpad work after

  • Weird flashing problem - cannot rename any file or folder in Movies

    I have a problem affecting just my Movies folder. Whenever I view it in the Finder, the edge of the Finder window will flash once every four seconds. If I am trying to rename an item within the Movies folder when the flash happens, I get dumped out o

  • Weird Access Problems - Really Need Your Advice

    This is complex and confusing, and I am not an IT expert. Let me provide background and symptoms: 1) I recently moved and transferred ISP providers from Cox to Adelphia. 2 My setup consists of Mac G5, a Powerbook, and an Airport Station. The internet

  • Quicktime causing weird FINDER problems

    Still running TIger 10.4.11 I downloaded 7.6 Quicktime and now my finder keeps flashing every few minutes. Everything on the Desktop AND the menu bar disappears for a second then comes back. Anyone else having this problem? G4 LaptopIt was my stuffit

  • Really weird color problems

    This is really strange. I have a feeling that this is just some setting that I accidentally tripped, but I can't figure it out. When I look at a picture file in the finder it looks fine. The colors look normal, etc. When I open that picture in any vi