sun.awt.windows.WToolkit是什么?

时间:2023-02-04 17:29:18

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

事件的来源是(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).

当我认为我只有两个来源时,java.awt。按钮和java.awt.Frame。当我按下鼠标时,我可以看到正在生成的两个事件,其中一个是sun.awt.windows。WToolkit是源,而另一个是按钮(当我点击按钮时)。

My questions are

我的问题是

  1. what is sun.awt.windows.WToolkit?
  2. sun.awt.windows.WToolkit是什么?
  3. why am I able to see two events on a single mouse press?
  4. 为什么我能在一个鼠标上看到两个事件?

2 个解决方案

#1


3  

The names speak for themselves: AWT stands for Abstract Window Toolkit which implies that the Toolkit is abstract and requires an actual implementation. sun.awt.windows.WToolkit is such an implementation for the Microsoft Windows plattform hence the W in its name. On other operating systems you will see different implementations, e.g. sun.awt.X11.XToolkit on Linux. If you just do a System.out.println(Toolkit.getDefaultToolkit()); you will see that the Toolkit’s string representation matches that of the event source which you see from time to time.

名称不言自明:AWT代表抽象窗口工具包,这意味着工具包是抽象的,需要实际的实现。sun.awt.windows。WToolkit是微软Windows plattform的一个实现,因此它的名字是W。在其他操作系统上,您将看到不同的实现,例如sun.awt.X11。XToolkit Linux上。如果您只执行一个System.out.println(Toolkit.getDefaultToolkit());您将看到工具箱的字符串表示与您不时看到的事件源的字符串表示相匹配。

I suggest you do a print of the entire event instead of just the source. Then you will see what these events are for. You will see what kind of events the toolkit generates. And you will see that a mouse click can generate up to three events: one for the press, one for the release and one if pressing and releasing happened at the same location which is considered a click.

我建议你把整个事件都打印出来,而不是只写源代码。然后你将会看到这些事件是为了什么。您将看到工具箱生成的事件类型。你会看到,鼠标点击可以产生三个事件:一个是媒体,一个是发布,一个是在被认为是点击的相同位置上发布和发布。

#2


0  

You're implementing ALL of the libraries by using the * character. So the output specifies where the source of event occurred.

您正在使用*字符来实现所有的库。因此,输出指定事件源发生的位置。

#1


3  

The names speak for themselves: AWT stands for Abstract Window Toolkit which implies that the Toolkit is abstract and requires an actual implementation. sun.awt.windows.WToolkit is such an implementation for the Microsoft Windows plattform hence the W in its name. On other operating systems you will see different implementations, e.g. sun.awt.X11.XToolkit on Linux. If you just do a System.out.println(Toolkit.getDefaultToolkit()); you will see that the Toolkit’s string representation matches that of the event source which you see from time to time.

名称不言自明:AWT代表抽象窗口工具包,这意味着工具包是抽象的,需要实际的实现。sun.awt.windows。WToolkit是微软Windows plattform的一个实现,因此它的名字是W。在其他操作系统上,您将看到不同的实现,例如sun.awt.X11。XToolkit Linux上。如果您只执行一个System.out.println(Toolkit.getDefaultToolkit());您将看到工具箱的字符串表示与您不时看到的事件源的字符串表示相匹配。

I suggest you do a print of the entire event instead of just the source. Then you will see what these events are for. You will see what kind of events the toolkit generates. And you will see that a mouse click can generate up to three events: one for the press, one for the release and one if pressing and releasing happened at the same location which is considered a click.

我建议你把整个事件都打印出来,而不是只写源代码。然后你将会看到这些事件是为了什么。您将看到工具箱生成的事件类型。你会看到,鼠标点击可以产生三个事件:一个是媒体,一个是发布,一个是在被认为是点击的相同位置上发布和发布。

#2


0  

You're implementing ALL of the libraries by using the * character. So the output specifies where the source of event occurred.

您正在使用*字符来实现所有的库。因此,输出指定事件源发生的位置。