Solved

Capturing a KeyEvent with a JWindow

Posted on 2002-07-21
4
287 Views
Last Modified: 2008-02-01
I'm having trouble getting a JWindow to capture a KeyEvent.  I looked in the PAQ's and found this example:

import java.awt.event.*;
import javax.swing.*;

public class JWindowEvents extends JWindow {

 public JWindowEvents() {
   addKeyListener(new KeyAdapter() {
     public void keyPressed(KeyEvent ke) {System.out.println("KeyPressed");}
     public void keyReleased(KeyEvent ke) {System.out.println("KeyReleased");}
     public void keyTyped(KeyEvent ke) { System.out.println("KeyTyped"); }
   });
 }
 public static void main(String[] args) {

   JWindowEvents jwe = new JWindowEvents(frame);
   jwe.setSize(200, 200);
   jwe.setLocation(200, 100);
   jwe.setVisible(true);

   jwe.requestFocus();
 }
}

... I added the 'jwe.requestFocus()' but it still doesn't manage to capture the KeyEvents.  I'm using the 1.4 SDK so I'm not sure if I should be going about it a different way now or not.

Any help would be great.
0
Comment
Question by:moshecristel
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7168436
I don't think a JWindow can actually recieve the focus so what you are trying to do will not work (as you have already discovered).
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 7168438
0
 

Author Comment

by:moshecristel
ID: 7168542
objects:

Bummer :(  It's good to know, though.  Thanks for the help.
0
 
LVL 92

Expert Comment

by:objects
ID: 7170556
Happy I could help :-)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
Increment alphanumeric sequence 6 80
bunnyEars challenge 6 64
Image decoding from Camera 3 47
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now