I have the following piece of code
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import javax.swing.*;
class QueueTest {
static int i=0;
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.setLayout(new FlowLayout());
f.setVisible(true);
Button b=new Button("button");
//b.setEnabled(false);
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);
}
protected void dispatchEvent(AWTEvent event)
{
System.out.println("The source of event ("+(i++)+") is
"+event.getSource());
super.dispatchEvent(event);
}
}
}
In the output i could sometimes see
The source of event is (78) sun.awt.windows.WToolkit@77ef83
when I think i have only two sources, the java.awt.Button
and the java.awt.Frame
. Also when I am pressing the mouse, I could see two events being generated for which one is sun.awt.windows.WToolkit
is the source and for the other is Button
(when I clicked on button).
My questions are
- what is sun.awt.windows.WToolkit?
- why am I able to see two events on a single mouse press?