Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4088881

ActionEvent not being properly consumed ...

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.4
    • client-libs
    • x86
    • windows_nt



      Name: rm29839 Date: 10/27/97


      import java.awt.*;
      import java.awt.event.*;

      // This is a potential bug in AWT JDK 1.1.4 on Win NT
      // Problem: ActionEvent not being properly consumed ...
      // Description: There is one frame and two modal dialogs. The frame contains
      // a text field. To show the first modal dialog type enter in the frame.
      // This in turn, will launch a modal dialog containing a text field. Now,
      // the ActionEvent of this text field will launch another modal dialog
      // that contains a close button, that subscribes to enter key. The ActionEvent
      // in the first modal dialog doesn't consume the event, and hence get's passed
      // to the second modal dialog, which responds by appearing and disappearing
      // very quickly.
      // Temporary Solution: Do not subsribe for action event in such text field.
      // Instead, subscribe to one of the key events. The solution is also
      // included in the source below, but has been commented out. So, to see
      // the solution, comment out the action event, and uncomment the key
      // released event.

      public class misbehavingModal extends Frame {
      public static void main (String[] args) {
      Frame f = new misbehavingModal ();
      f.pack ();
      f.setSize (300, 200);
      f.setVisible (true);
      }

      public misbehavingModal () {
      setLayout (new FlowLayout ());
      TextField tf = new TextField (10);
      add (tf);
      KeyListener kl = new KeyAdapter () {
      public void keyReleased (KeyEvent ke) {
      if (
      (ke.getKeyCode () == KeyEvent.VK_D) ||
      (ke.getKeyCode () == KeyEvent.VK_F) ||
      (ke.getKeyCode () == KeyEvent.VK_ENTER)
      ) {
      System.out.println ("Showing dialog ...");
      Dialog d = new textDialog (misbehavingModal.this);
      d.pack ();
      d.setVisible (true);
      }
      }
      };
      tf.addKeyListener (kl);
      }
      }

      class textDialog extends Dialog {
          public textDialog (final Frame f) {
              super (f, true);
              setLayout (new FlowLayout ());
              TextField tf = new TextField (10);
              tf.addActionListener (
                  new ActionListener () {
                      public void actionPerformed (ActionEvent e) {
                          almostModalDialog d = new almostModalDialog (f);
                          d.pack ();
                          d.setVisible (true);
                      }
                  }
              );
              /*
              tf.addKeyListener (
                  new KeyAdapter () {
                      public void keyReleased (KeyEvent e) {
                          if (e.getKeyCode () == KeyEvent.VK_ENTER) {
                              almostModalDialog d = new almostModalDialog (f);
                              d.pack ();
                              d.setVisible (true);
                          }
                      }
                  }
              );
              */
              add (tf);
          }
      }

      class almostModalDialog extends Dialog {
      public almostModalDialog (Frame f) {
      super (f, true);
      setLayout (new FlowLayout ());
      Button button = new Button ("Close");
      ActionListener al = new ActionListener () {
      public void actionPerformed (ActionEvent ae) {
      dispose ();
      }
      };
      button.addActionListener (al);
      KeyListener kl = new KeyAdapter () {
      public void keyReleased (KeyEvent ke) {
      if (ke.getKeyCode () == KeyEvent.VK_ENTER) {
      dispose ();
      }
      }
      };
      button.addKeyListener (kl);
      add (button);
      }

      public Dimension getPreferredSize () {
      return new Dimension (100, 100);
      }
      }
      company - , email - ###@###.###
      ======================================================================

            ibdsunw Ibd Ibd (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: