Eric,

This is a bit off topic (more general Swing/AWT stuff) but if it helps...

You need to give a little more detail for what this is for. The problem is
that when a window isn't visible, It doesn't have the focus from the
keyboard. So no keyevents ever get to it.

So something needs to be a the key listener to evoke the window you want the
following code does what you want sort of.... Once the window in question is
open, it can listen for it's own key events to close it.

In my example the smaller window f2 will listen for the keyPressed... and
then the larger window will listen for the keyReleased. The larger window
would be the window that stays open only as long as you hold down alt-e.


Jeremy E. Denton
Software Developer
Galdos Systems Inc.
______________________________________________________________
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;



public class KeyFrame extends JFrame {
  JFrame thisFrame = this;
  public KeyFrame() {
    thisFrame = this;
    addKeyListener(new KeyListener () {
      public void keyPressed(KeyEvent ke) {
      }
      public void keyReleased(KeyEvent ke) {
        if (ke.isAltDown() && (ke.getKeyCode() == KeyEvent.VK_E))
          thisFrame.setVisible(false);
      }
      public void keyTyped(KeyEvent ke) {}
    });
  }
  public static void main(String[] args) {
     final KeyFrame f1 = new KeyFrame();
    f1.setSize(300,300);


   JFrame f2 = new JFrame();
    f2.setSize(100,100);
    f2.setVisible(true);
    f2.addKeyListener(new KeyListener () {
      public void keyPressed(KeyEvent ke) {
        System.out.println(ke);
        System.out.println(ke);
        if (ke.isAltDown() && (ke.getKeyCode() == KeyEvent.VK_E))
           f1.setVisible(true);
      }
      public void keyReleased(KeyEvent ke) {
       }
      public void keyTyped(KeyEvent ke) {}
    });

  }
}
____________________________________________________________________________
____________
> -----Original Message-----
> From: Discussion list for Java 3D API
> [mailto:[EMAIL PROTECTED]]On Behalf Of Malguy, Eric G.
> Sent: Thursday, January 11, 2001 1:09 PM
> To: [EMAIL PROTECTED]
> Subject: [JAVA3D] short key help
>
>
> Evening folks,
>
> I need to open a GUI when the user push a defined (e.g. Alt+E) key and the
> window need to stay up ONLY as long
> as the user hold the key down.  When the key is released the
> window closes.
> Does anyone have an example for my problem?
>
> Thanks for your help,
>
> Eric
>
>                              \\\|///
>                            \\  ~ ~  //
>                             (  @ @  )
> --------------------------oOOo-(_)-oOOo--------------------------------
>
>      _/_/_/_/  _/_/_/_/  _/_/_/_/_/  _/_/_/_/   Eric Malguy
>     _/        _/    _/      _/      _/         Software Engineer
>    _/_/_/_/  _/_/_/_/      _/      _/        Advanced Systems Group
>         _/  _/    _/      _/      _/        Alexandria, VA(703)684-6244
>  _/_/_/_/  _/    _/  _/_/_/_/_/  _/_/_/_/  [EMAIL PROTECTED]
> -----------------------------------Oooo.-------------------------------
>                           .oooO     (   )
>                           (   )      ) /
>                            \ (      (_/
>                             \_)
>
> ==================================================================
> =========
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to