java.awt.Toolkit.addAWTEventListener()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中java.awt.Toolkit.addAWTEventListener()方法的一些代码示例,展示了Toolkit.addAWTEventListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolkit.addAWTEventListener()方法的具体详情如下:
包路径:java.awt.Toolkit
类名称:Toolkit
方法名:addAWTEventListener

Toolkit.addAWTEventListener介绍

[英]Adds an AWTEventListener to receive all AWTEvents dispatched system-wide that conform to the given eventMask.

First, if there is a security manager, its checkPermission method is called with an AWTPermission("listenToAllAWTEvents") permission. This may result in a SecurityException.

eventMask is a bitmask of event types to receive. It is constructed by bitwise OR-ing together the event masks defined in AWTEvent.

Note: event listener use is not recommended for normal application use, but are intended solely to support special purpose facilities including support for accessibility, event record/playback, and diagnostic tracing. If listener is null, no exception is thrown and no action is performed.
[中]添加一个AWTEventListener,以接收符合给定eventMask的系统范围内已调度的所有AWTEvent。
首先,如果有一个安全管理器,它的checkPermission方法将被调用,并具有AWTPermission("listenToAllAWTEvents")权限。这可能会导致SecurityException。
eventMask是要接收的事件类型的位掩码。它是通过将AWTEvent中定义的事件掩码按位或组合在一起构建的。
注意:不建议在正常应用程序中使用事件侦听器,但仅用于支持特殊用途的设施,包括支持可访问性、事件记录/回放和诊断跟踪。如果侦听器为null,则不会引发异常,也不会执行任何操作。

代码示例

代码示例来源:origin: stackoverflow.com

import java.awt.AWTEvent;
import java.awt.MouseInfo;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;

import javax.swing.JFrame;

public class Application1 {
  public static void main(String[] args) {
    Toolkit.getDefaultToolkit().addAWTEventListener(
     new Listener(), AWTEvent.MOUSE_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }

  private static class Listener implements AWTEventListener {
    public void eventDispatched(AWTEvent event) {
      System.out.print(MouseInfo.getPointerInfo().getLocation() + " | ");
      System.out.println(event);
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

@Override
public void addNotify() {
  super.addNotify();
  if (!Boolean.TRUE.equals(getClientProperty(PROP_JDEV_DISABLE_OVERFLOW))) {
  addComponentListener(getComponentListener());
  Toolkit.getDefaultToolkit().addAWTEventListener(getAWTEventListener(), AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
}

代码示例来源:origin: com.github.insubstantial/flamingo

@Override
  public Object run() {
    tk.addAWTEventListener(WindowTracker.this,
        AWTEvent.MOUSE_EVENT_MASK
            | AWTEvent.MOUSE_MOTION_EVENT_MASK
            | AWTEvent.MOUSE_WHEEL_EVENT_MASK
            | AWTEvent.WINDOW_EVENT_MASK);
    return null;
  }
});

代码示例来源:origin: net.sf.tinylaf/tinylaf

public Object run() {
          Toolkit.getDefaultToolkit().addAWTEventListener(
            mouseHandler,
            AWTEvent.MOUSE_EVENT_MASK
              | AWTEvent.MOUSE_MOTION_EVENT_MASK
              | AWTEvent.MOUSE_WHEEL_EVENT_MASK);

//                    System.out.println("escapeMenuHandler added");
          return null;
        }
      });

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

void install() {
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK);
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_WHEEL_EVENT_MASK);
}

代码示例来源:origin: jawi/ols

/**
 * Called by Felix DM when this component is started.
 */
public void start()
{
 // Install us as a global window state listener...
 Toolkit.getDefaultToolkit().addAWTEventListener( this, AWTEvent.WINDOW_EVENT_MASK );
 this.logger.log( LogService.LOG_DEBUG, "AWT Window state listener installed..." );
}

代码示例来源:origin: magefree/mage

Toolkit.getDefaultToolkit().addAWTEventListener(event -> handleEvent(event), AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);

代码示例来源:origin: net.java.dev.jna/jna-platform

@Override
public void addNotify() {
  super.addNotify();
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.CONTAINER_EVENT_MASK);
}
@Override

代码示例来源:origin: net.java.dev.jna/platform

public void addNotify() {
  super.addNotify();
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.CONTAINER_EVENT_MASK);
}
public void removeNotify() {

代码示例来源:origin: org.gephi/desktop-datalab

@Override
protected void componentActivated() {
  super.componentActivated();
  java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
}

代码示例来源:origin: org.japura/japura-gui

public void apply() {
 try {
  Toolkit.getDefaultToolkit().addAWTEventListener(getListener(),
    Long.MAX_VALUE);
 } catch (SecurityException e) {
  e.printStackTrace();
  // ignore
 }
}

代码示例来源:origin: notzippy/JALOPY2-MAIN

public void addNotify()
{
  super.addNotify();
  Toolkit.getDefaultToolkit().addAWTEventListener(
    this,
    AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK
    | AWTEvent.MOUSE_MOTION_EVENT_MASK);
}

代码示例来源:origin: us.ihmc.thirdparty.jinput/jinput

protected AWTKeyboard() {
  super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
  resizeEventQueue(EVENT_QUEUE_DEPTH);
}

代码示例来源:origin: jinput/jinput

protected AWTKeyboard() {
  super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
  resizeEventQueue(EVENT_QUEUE_DEPTH);
}

代码示例来源:origin: halirutan/IntelliJ-Key-Promoter-X

@Override
public void initComponent() {
  ActionManager.getInstance().addAnActionListener(this);
  long eventMask = AWTEvent.MOUSE_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_STATE_EVENT_MASK;
  Toolkit.getDefaultToolkit().addAWTEventListener(this, eventMask);
}

代码示例来源:origin: com.metsci.glimpse/glimpse-wizard

public void showErrorPopup( Component anchor, Dimension size, Collection<WizardError> errors )
{
  this.panel.setErrors( errors );
  Dimension anchorSize = anchor.getSize( );
  Point point = new Point( 0, ( int ) anchorSize.getHeight( ) );
  SwingUtilities.convertPointToScreen( point, anchor );
  this.setLocation( point );
  this.setSize( size );
  this.setVisible( true );
  this.isOpen = true;
  Toolkit.getDefaultToolkit( ).addAWTEventListener( this.listener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK );
}

代码示例来源:origin: JetBrains/jediterm

@Override
public void installUI(JComponent c) {
 super.installUI(c);
 updateStyle(Style.CURRENT.get());
 processReferences(this, null, null);
 AWTEventListener listener = MOVEMENT_LISTENER.getAndSet(null); // add only one movement listener
 if (listener != null) Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_MOTION_EVENT_MASK);
}

代码示例来源:origin: com.synaptix/SynaptixSwing

public JChoixPanel() {
  super(new VerticalLayout(5));
  map1 = new HashMap<E, JSelectedPanel>();
  map2 = new HashMap<JSelectedPanel, E>();
  this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  MyMouseAdapter mouseAdapter = new MyMouseAdapter();
  this.addMouseListener(mouseAdapter);
  this.addMouseMotionListener(mouseAdapter);
  Toolkit.getDefaultToolkit().addAWTEventListener(
      new MyAWTEventListener(), AWTEvent.MOUSE_EVENT_MASK);
}

代码示例来源:origin: net.java.dev.jna/jna-platform

@Override
public void addNotify() {
  super.addNotify();
  Window w = SwingUtilities.getWindowAncestor(this);
  setSize(getParent().getSize());
  w.addComponentListener(listener);
  w.addWindowListener(listener);
  Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK);
}

代码示例来源:origin: net.java.dev.jna/platform

public void addNotify() {
  super.addNotify();
  Window w = SwingUtilities.getWindowAncestor(this);
  setSize(getParent().getSize());
  w.addComponentListener(listener);
  w.addWindowListener(listener);
  Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK);
}

相关文章