Hi,
I am using jdk1.1.18 and jfc-swing-1.1.1 in my appication. This is an
embedded system running (what I think is) JWorks on VxWorks, which
(again, I guess) is based on the combination I mentioned above and I
dont have the option of upgrading to later java versions.
I want to capture all the KeyEvents in the system (lowlevel ones like
KEY_RELEASED, not just ActionEvents or KEY_TYPED) , irrespsective of
which component has the focus currently. The root container is a
JWindow with a custom (Drawer) layout.
In jdk1.4, I would have used any of the following:
1. Toolkit.addAWTEventListener(new MyAWTListener());
2. FocusManager.setCurrentManager(new MyFocusManager());
3. setVisible(true) on the glasspane of my JWindow, capture events and
re-dispatch them.
In fact, #2 sort of works in jfc-swing-1.1. But I dont get low level
events like KEY_RELEASED. If the component with focus is a text-aware
one (like JTextField), then I get both KEY_PRESSED and KEY_TYPED, but
not KEY_RELEASED. But If the component in focus is a JButton, I get
only KEY_TYPED.
I have 3 questions:
a. Is there an equvalent of #1 in jdk1.1..8?
b. Is there a way to make #2 give me KEY_RELEASED events?
c. Would #3 above work? How do I do it? Again, I dont seem to be
getting KeyEvents at all, even after doing
enableEvents(AWTEvent.KEY_EVENT_MASK) on MyJPanel. I get all the mouse
events, though. But then, how do I re-dispatch events?
I have searched through this forum and google a lot. But couldn't find
any solution.
Thanks
John McGrath - 26 Oct 2004 02:24 GMT
> a. Is there an equvalent of #1 in jdk1.1..8?
JDK 1.1.8 has an EventQueueListener class and an addEventQueueListener()
method in the EventQueue class. It looks like it notifies listeners when
an event is posted to the event queue, which may serve your needs.
The method is package private, so you will need to employ some trickery to
get at it. Unfortunately, you cannot use the Reflection setAccessible()
methods in Java 1.1. But then I do not think that package sealing existed
either, so you should be able to place a class in the java.awt package to
give you access.

Signature
Regards,
John McGrath
Kannan S - 27 Oct 2004 19:17 GMT
> JDK 1.1.8 has an EventQueueListener class and an addEventQueueListener()
> method in the EventQueue class. It looks like it notifies listeners when
> an event is posted to the event queue, which may serve your needs.
Yep, I saw that in the src. And it works in the vanilla
jdk1.1.8/jfc-1.1.1 combination. But I get a ClassNotFoundError while
trying the same code in JWorks (or whatever Java is running in my
embedded box), even if I patch the local classes.zip on that box.
Any ideas?
Also, would it be a license violation if I write a class called
"java.awt.EventCopier", which uses EventQueue.addEventQueueListener()
and has a public method to relay events outside java.awt and then add
it to classes.zip?
Well, I guess its ok for the demo. May be by the time I reach the
release date, I'd find a better solution :-)
Thanks
Paul Lutus - 27 Oct 2004 22:46 GMT
/ ...
> Also, would it be a license violation if I write a class called
> "java.awt.EventCopier", which uses EventQueue.addEventQueueListener()
> and has a public method to relay events outside java.awt and then add
> it to classes.zip?
AFAIK yes -- if you try to redistribute the zip file.

Signature
Paul Lutus
http://www.arachnoid.com
Babu Kalakrishnan - 26 Oct 2004 06:33 GMT
> I am using jdk1.1.18 and jfc-swing-1.1.1 in my appication. This is an
> embedded system running (what I think is) JWorks on VxWorks, which
[quoted text clipped - 5 lines]
> which component has the focus currently. The root container is a
> JWindow with a custom (Drawer) layout.
I've forgotten the exact sequence in which JDK 1.1.x used to process
events, but I seem to vaguly remember that it was mostly processed
through the dispatchEvent / processEvent methods of the topmost
heavyweight parent of a component. If the only heavyweight component
you're using is the top level container (JWindow), try overriding the
processEvent method (or dispatchEvent / dispatchEventImpl if they can be
overridden - they are final and package protected respectively in later
versions of the JDK) and see if you're getting all events.
BK
Kannan S - 27 Oct 2004 19:20 GMT
> I've forgotten the exact sequence in which JDK 1.1.x used to process
> events, but I seem to vaguly remember that it was mostly processed
[quoted text clipped - 4 lines]
> overridden - they are final and package protected respectively in later
> versions of the JDK) and see if you're getting all events.
That is what I too understood from the src. But the following code
doesn't give me any events, even in the vanilla jdk-1.1.8/jfc-1.1.1
combination. The AWT version of it works, though. ie. If I replace
JFrame with a Frame and all other JComponents with their AWT
counterparts.
=====
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEventListenerImpl {
public static void main(String args[]) {
MyFrame frame = new MyFrame();
Container c = frame.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("Button"));
//c.add(new JCheckbox("Checkbox"));
c.add(new JTextField("TextField"));
c.add(new JTextArea("TextArea"));
frame.setSize(200, 200);
frame.setVisible(true);
}
}
class MyFrame extends JFrame {
public boolean handleEvent(Event event) {
if(event.id == Event.KEY_PRESS) {
System.out.println("KeyPressed: " + event.key);
} else if(event.id == Event.KEY_RELEASE) {
System.out.println("KeyReleased: " + event.key);
}
return super.handleEvent(event);
}
}
====
Any clues?
Thanks
Babu Kalakrishnan - 28 Oct 2004 06:30 GMT
> class MyFrame extends JFrame {
>
[quoted text clipped - 9 lines]
> }
> }
The handleEvent method was the JDK 1.0 way of processing events and was
replaced by dispatchEvent/processEvent in 1.1. As far as I could see
from JDK 1.4 sources, no events are passed to the handleEvent method.
Did you try overriding the processEvent method instead ?
BK
Kannan S - 28 Oct 2004 16:44 GMT
> The handleEvent method was the JDK 1.0 way of processing events and was
> replaced by dispatchEvent/processEvent in 1.1. As far as I could see
> from JDK 1.4 sources, no events are passed to the handleEvent method.
>
> Did you try overriding the processEvent method instead ?
This seems to be working, after I do
enableEvents(AWTEvent.KEY_EVENT_MASK) on the JWindow. But thats ok.
A minor point to note is that if the focus is currently on a JButton
and if I press the space-bar, then I get only KEY_TYPED. This could be
because JButton uses KeyEvents to do its own Actions. But any other
key on the JButton gives me PRESSED, TYPED and RELEASED. I guess this
would do for the moment, as I'm not particular about the space-bar.
Thanks a lot.
--kannan
Fred L. Kleinschmidt - 27 Oct 2004 15:05 GMT
> Hi,
>
[quoted text clipped - 26 lines]
>
> b. Is there a way to make #2 give me KEY_RELEASED events?
You have to realize that not all hardware is capable of generating a
KEY_RELEASED event.
> c. Would #3 above work? How do I do it? Again, I dont seem to be
> getting KeyEvents at all, even after doing
[quoted text clipped - 5 lines]
>
> Thanks

Signature
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225