I have the following piece of code
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import javax.swing.*;
class QueueTest {
public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
EventQueue eventQueue =
Toolkit.getDefaultToolkit().getSystemEventQueue();
eventQueue.push(new MyEventQueue());
Frame f=new Frame();
f.setSize(400,400);
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(150,150);
f.setVisible(true);
Button b=new Button("button");
f.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
System.out.println("button is clicked");
}
});
}
private static class MyEventQueue extends EventQueue {
public void postEvent(AWTEvent theEvent) {
// System.out.println("Event Posted");
System.out.println("The source of event is "+theEvent.getSource());
super.postEvent(theEvent);
}
}
}
I have written a custom EventQueue
. This is working in swing when I've replaced Frame
with JFrame
and Button
with JButton
. But why isn't this working for AWT components?
When i have resized the frame, clicked on the button the control is not entered into the postEvent()
method. But in swing, it is entered. Why is it so?
Aren't events placed in the EventQueue
in AWT? Also who posts the events to this EventQueue
? Windows kernel?
Kindly, reply me.