Package java.awt.event

Examples of java.awt.event.WindowEvent


      if (frame != null) {
  if (frame instanceof JInternalFrame)
    ((JInternalFrame) frame).doDefaultCloseAction();
  else
    ((Window) frame).dispatchEvent(
        new WindowEvent(
      (Window) frame, WindowEvent.WINDOW_CLOSING));
      }
     
    } else {
      boolean help = ((commandArgs.length > 1)
View Full Code Here


   *
   * 覆盖对话框的销毁方法,默认的dispose可能造成线程问题,引起CPU过高
   *
   */
  public void dispose(){
    dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }
View Full Code Here

    public void handleEvent (Event e) {
      switch (e.type) {
        case SWT.Deiconify:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEICONIFIED));
            }
          });
          break;
        case SWT.Iconify:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ICONIFIED));
            }
          });
          break;
      }
    }
  };
  Shell shell = parent.getShell ();
  shell.addListener (SWT.Deiconify, shellListener);
  shell.addListener (SWT.Iconify, shellListener);
 
  /*
  * Generate the appropriate events to activate and deactivate
  * the embedded frame. This is needed in order to make keyboard
  * focus work properly for lightweights.
  */
  Listener listener = new Listener () {
    public void handleEvent (Event e) {
      switch (e.type) {
        case SWT.Dispose:
          Shell shell = parent.getShell ();
          shell.removeListener (SWT.Deiconify, shellListener);
          shell.removeListener (SWT.Iconify, shellListener);
          parent.setVisible(false);
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              try {
                frame.dispose ();
              } catch (Throwable e) {}
            }
          });
          break;
        case SWT.FocusIn:
        case SWT.Activate:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
                frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_GAINED));
              } else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
                frame.dispatchEvent (new WindowEvent (frame, 207 /*WindowEvent.WINDOW_GAINED_FOCUS*/));
              } else {
                if (frame.isActive()) return;
                try {
                  Class clazz = frame.getClass();
                  Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
                  if (method != null) method.invoke(frame, new Object[]{new Boolean(true)});
                } catch (Throwable e) {}
              }
            }
          });
          break;
        case SWT.Deactivate:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
                frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_LOST));
              } else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, 208 /*WindowEvent.WINDOW_LOST_FOCUS*/));
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
              } else {
                if (!frame.isActive()) return;
                try {
                  Class clazz = frame.getClass();
                  Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
View Full Code Here

    @Override
    public void actionPerformed(ActionEvent event) {
      log.fine("Menu Action: " + event.getActionCommand());
      if (event.getActionCommand()
          .equals(rb.getString("menu.file.close"))) {
        WindowEvent closingEvent = new WindowEvent(MainWindow.this,
            WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue()
            .postEvent(closingEvent);
      } else if (event.getActionCommand().equals(
          rb.getString("menu.file.new"))) {
View Full Code Here

        JMenuItem mitExit = new JMenuItem("Exit");
        mitExit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                WindowEvent we;
                we = new WindowEvent(mainFrame, WindowEvent.WINDOW_CLOSING);
                mainFrame.dispatchEvent(we);
            }
        });
        menuFile.add(mitExit);
       
View Full Code Here

    public void handleEvent (Event e) {
      switch (e.type) {
        case SWT.Deiconify:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEICONIFIED));
            }
          });
          break;
        case SWT.Iconify:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ICONIFIED));
            }
          });
          break;
      }
    }
  };
  Shell shell = parent.getShell ();
  shell.addListener (SWT.Deiconify, shellListener);
  shell.addListener (SWT.Iconify, shellListener);
 
  /*
  * Generate the appropriate events to activate and deactivate
  * the embedded frame. This is needed in order to make keyboard
  * focus work properly for lightweights.
  */
  Listener listener = new Listener () {
    public void handleEvent (Event e) {
      switch (e.type) {
        case SWT.Dispose:
          Shell shell = parent.getShell ();
          shell.removeListener (SWT.Deiconify, shellListener);
          shell.removeListener (SWT.Iconify, shellListener);
          parent.setVisible(false);
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              try {
                frame.dispose ();
              } catch (Throwable e) {}
            }
          });
          break;
        case SWT.Activate:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
                frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_GAINED));
              } else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
                frame.dispatchEvent (new WindowEvent (frame, 207 /*WindowEvent.WINDOW_GAINED_FOCUS*/));
              } else {
                try {
                  /* Initialize the default focus traversal policy */
                  Class clazz = frame.getClass();
                  Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
                  if (method != null) method.invoke(frame, new Object[]{new Boolean(true)});
                } catch (Throwable e) {}
              }
            }
          });
          break;
        case SWT.Deactivate:
          EventQueue.invokeLater(new Runnable () {
            public void run () {
              if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
                frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_LOST));
              } else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
                frame.dispatchEvent (new WindowEvent (frame, 208 /*WindowEvent.WINDOW_LOST_FOCUS*/));
                frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
              } else {
                try {
                  /* Initialize the default focus traversal policy */
                  Class clazz = frame.getClass();
                  Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
View Full Code Here

      Assert.assertFalse(listener.isLogAll());
   }
  
   private WindowEvent createWindowEvent(int eventId)
   {
      WindowEvent result = new WindowEvent(window, eventId);
      return result;
   }
View Full Code Here

   }
  
   @Test
   public void testOnClosing()
   {
      WindowEvent event = createWindowEvent(WindowEvent.WINDOW_CLOSING);
      MultifunctionalWindowListener listener = new MultifunctionalWindowListener();
      Assert.assertTrue(window.isDisplayable());
      listener.windowClosing(event);
      Assert.assertTrue(window.isDisplayable());
      listener = MultifunctionalWindowListener.createDisposeOnClosingListener();
View Full Code Here

    * Currently just tests that no exception occurs.
    */
   @Test
   public void testWindowActivated()
   {
      WindowEvent event = createWindowEvent(WindowEvent.WINDOW_ACTIVATED);
      MultifunctionalWindowListener listener = new MultifunctionalWindowListener();
      listener.windowActivated(event);
     
   }
View Full Code Here

    * Currently just tests that no exception occurs.
    */
   @Test
   public void testWindowClosed()
   {
      WindowEvent event = createWindowEvent(WindowEvent.WINDOW_CLOSED );
      MultifunctionalWindowListener listener = new MultifunctionalWindowListener();
      listener.windowClosed(event);
   }
View Full Code Here

TOP

Related Classes of java.awt.event.WindowEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.