Beispiel #1
0
  public void start(KeyboardManager keymgr, Window root, RunQueue rqueue) {
    EventListener listener = new EventListener();
    try {
      // try to add a global event listener
      Toolkit.getDefaultToolkit().addAWTEventListener(listener, EVENT_MASK);
    } catch (SecurityException se) {
      // fall back to listening to our main window
      if (root != null) {
        root.addKeyListener(listener);
        root.addMouseListener(listener);
        root.addMouseMotionListener(listener);
      }
    }

    // and tie into the keyboard manager if one is provided
    if (keymgr != null) {
      keymgr.registerKeyObserver(
          new KeyboardManager.KeyObserver() {
            public void handleKeyEvent(int id, int keyCode, long timestamp) {
              handleUserActivity();
            }
          });
    }

    // register an interval to periodically check our last activity time
    new Interval(rqueue) {
      @Override
      public void expired() {
        checkIdle();
      }
    }.schedule(_toIdleTime / 3, true);
  }
 /**
  * Installs the necessary Listeners on the parent <code>Window</code>, if there is one.
  *
  * <p>This takes the parent so that cleanup can be done from <code>removeNotify</code>, at which
  * point the parent hasn't been reset yet.
  *
  * @param parent The parent of the JRootPane
  */
 private void installWindowListeners(JRootPane root, Component parent) {
   if (parent instanceof Window) {
     window = (Window) parent;
   } else {
     window = SwingUtilities.getWindowAncestor(parent);
   }
   if (window != null) {
     if (mouseInputListener == null) {
       mouseInputListener = createWindowMouseInputListener(root);
     }
     window.addMouseListener(mouseInputListener);
     window.addMouseMotionListener(mouseInputListener);
   }
 }
Beispiel #3
0
  // init
  public void init() {
    super.init();
    mouse = new Point();
    center = new Point();
    image = new Point();
    centering = false;

    try {
      robot = new Robot();
      recenterMouse();
      mouse.x = center.x;
      mouse.y = center.y;
    } catch (Exception e) {
      System.out.println("Exception 1");
    }

    Window w = s.getFullScreenWindow();
    w.addMouseMotionListener(this);
    w.addKeyListener(this);
    bg = new ImageIcon("/Users/Ole/Desktop/undefined/images/bg.jpg").getImage();
  }