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

keyDown not called on subclasses of Component (1.1.x only)

XMLWordPrintable

    • generic, x86
    • generic, windows_95



      Name: dgC58589 Date: 11/19/97


      I have a commercial application that subclasses
      component. We sell mostly to those who require
      JDK 1.0.2 to cover most browsers, but we are
      starting to move in the direction of JDK 1.1+.

      I have a component that subclasses
      java.awt.Component. In JDK 1.0.2, the keyDown
      method of my subclass of Component gets called,
      but it does not get called in JDK 1.1.1, 1.1.2,
      1.1.3. I've traced the call stack, andComponent.handleEvent is calling mouseDown,
      and the right thing happens, but when it calls
      keyDown, the wrong thing happens.

      When I run this test application on JDK 1.0.2,
      it runs great. When I use the exact same
      class file in JDK 1.1+, then again, mouseDown
      events are captured, but keyDown events
      are not passed to my class (Component.keyDown
      is called instead.)

      Compiling the applet in JDK 1.1.3, 1.1.4, does
      not make a difference, still the same result.

      The STRANGE thing is that this is NOT a problem
      in the Netscape 4.02 or Internet Explorer 4.0
      JVM's. The applet below, compiled with
      JDK 1.1.4, works as it should.

      So therefore, this may not be a problem for
      most of our customers, but then again it may.
      In the meantime, it slows down our transition
      to JDK1.1 because it makes the testing process
      difficult.

      Here is the test application....

      //file: TestKeyDown.java
      import java.applet.Applet;
      import java.awt.*;


      public class TestKeyDown extends Applet {

        TextField feedback;
        public void init() {
          setLayout(new BorderLayout());
          Panel bottomPanel = new Panel();
          bottomPanel.setBackground(Color.white);
          feedback = new TextField("", (50)) ;
          feedback.setEditable(false) ;
          bottomPanel.add(feedback) ;
          add("South", bottomPanel);

          MyCanvas canvas = new MyCanvas(this);
          add("Center", canvas);
        }

        // Posts messages to the feedback window of the applet.
        public void messageFeedback (String str) {
          if (str == null) str = "";
          feedback.setText( str ) ;
        }

      }

      class MyCanvas extends Canvas {

        TestKeyDown _applet;

        public MyCanvas(TestKeyDown applet) {
          _applet = applet;
          //setSize(200, 200);
          setBackground(Color.red);
        }

      // public boolean handleEvent(Event evt) {
      // if (evt.id == Event.KEY_PRESS || evt.id == Event.KEY_ACTION)
      // return keyDown(evt, evt.key);
      // else return super.handleEvent(evt);
      // }

        public boolean keyDown(Event evt, int key) {
          setBackground(Color.blue);
          repaint();
          _applet.messageFeedback("Key Down " + key);
          return true;
        }

        public boolean mouseUp(Event evt, int x, int y) {
          setBackground(Color.white);
          repaint();
          _applet.messageFeedback("Mouse Up " + x + " " + y);
          return true;
        }

        public boolean mouseDown(Event evt, int x, int y) {
          setBackground(Color.red);
          repaint();
          _applet.messageFeedback("Mouse Down " + x + " " + y);
          return true;
        }

      }


      Here is the test HTML...

      <html>
      <head>
      <title> Test Key Down on Applet in JDK 1.1</title>
      </head>
      <body>
      <h2>Testing Key Down on subclass of Component in JDK 1.1.x</h2>
      <applet code="TestKeyDown.class" WIDTH=400 HEIGHT=400>
      </applet>

      </body>
      </html>
      (Review ID: 20189)
      ======================================================================

            rramsunw Ranganathan Ram (Inactive)
            dgrahamcsunw David Graham-cumming (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: