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

Java Plugin does not consume a keyEvent when consume() is used

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      04
    • CPU:
      generic, x86
    • OS:
      generic, windows_98, windows_nt
    • Verification:
      Verified

      Backports

        Description



        Name: rlT66838 Date: 12/07/99


        java version "1.2.2"
        Classic VM (build JDK-1.2.2-001,native threads,symcjit)

        When using the Java Plug-in in IE 5.0 it does not consume a keyEvent when
        consume () is used. (ie. If you press F1 the windows help comes up) it does
        not do this if you use the IE 5.0 VM

        HTML page with the applet tag using HTMLConverter to use the plug -in:

        <html><!--"CONVERTED_APPLET"-->
        <!-- CONVERTER VERSION 1.0 -->
        <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
        WIDTH = 300 HEIGHT = 200 NAME = main
        codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-
        win32.cab#Version=1,2,0,0">
        <PARAM NAME = CODE VALUE = TestKey >
        <PARAM NAME = CODEBASE VALUE = http://192.168.1.1:8080/ >
        <PARAM NAME = NAME VALUE = main >

        <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
        <COMMENT>
        <EMBED type="application/x-java-applet;version=1.2" java_CODE = TestKey
        java_CODEBASE = http://192.168.1.1:8080/ NAME = main WIDTH = 300 HEIGHT = 200
        pluginspage="http://java.sun.com/products/plugin/1.2/plugin-
        install.html"><NOEMBED></COMMENT>

        </NOEMBED></EMBED>
        </OBJECT>

        <!--
        <APPLET CODE = TestKey CODEBASE = http://192.168.1.1:8080/ WIDTH = 300 HEIGHT
        = 200 NAME = main >


        </APPLET>
        -->
        <!--"END_CONVERTED_APPLET"-->

        </html>


        Sample code that recreates the problem:

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

        public class TestKey extends Applet
        {
        public TestKey ()
        {
        TextField tf = new TextField();
        tf.addKeyListener(new KeyEventHandler());;
        tf.setFont(new Font("Courier",Font.PLAIN,14));
        add(tf,BorderLayout.CENTER);
        show();
        }
        public void init()
        {
        new TestKey ();
        }
        }

        class KeyEventHandler extends KeyAdapter
        {
        public void keyPressed (KeyEvent evt)
        {
        printKey(evt);
        }
        public void keyReleased(KeyEvent evt)
        {
        printKey(evt);
        }
        public void keyTyped(KeyEvent evt)
        {
        printKey(evt);
        }
        void printKey(KeyEvent evt)
        {
        switch (evt.getID())
        {
        case KeyEvent.KEY_TYPED:
        System.out.print("KEY_TYPED");
        break;
        case KeyEvent.KEY_PRESSED:
        System.out.print("KEY_PRESSED");
        break;
        case KeyEvent.KEY_RELEASED:
        System.out.print("KEY_RELEASED");
        break;
        }
        System.out.print(" : char="+evt.getKeyChar()
        +"("+(int)evt.getKeyChar()+")");
        System.out.print(" code="+evt.getKeyCode());
        if (evt.isActionKey())
        {
        System.out.print(" actionkey");
        if (evt.getKeyCode() == KeyEvent.VK_F1)
        evt.consume();

        }
        System.out.println();

        }
        }
        (Review ID: 98758)
        ======================================================================

        Name: yyT116575 Date: 01/31/2001


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

        I don't seem to be able to use consume() in a KeyTyped() routine. I know that heaps of developers have mentioned this one, but I have never seen anyone state the problem as simply as the following code demonstrates:

        I have the following HTML code:
        ===============================
        <HTML>
          <HEAD>
            <TITLE>TestBug</TITLE>
          </HEAD>
          <BODY>
            <APPLET CODE="TestBug.class" WIDTH=200 HEIGHT=40>
            </APPLET>
          </BODY>
        </HTML>

        And the following Java code for the TestBug class:
        ==================================================
        import java.awt.*;
        import java.awt.event.*;

        public class TestBug extends java.applet.Applet implements KeyListener {
          FlowLayout AppLayout = new FlowLayout(FlowLayout.CENTER);
          Panel mainPanel = new Panel();
          Label lbl = new Label("Enter Something:", Label.LEFT);
          TextField txt = new TextField(5);

          public void init() {
            mainPanel.setLayout(AppLayout);
            mainPanel.add(lbl);
            mainPanel.add(txt);
            txt.addKeyListener(this);
            add(mainPanel);
          }

          public void keyPressed(KeyEvent e) {}
          public void keyReleased(KeyEvent e) {}
          public void keyTyped(KeyEvent e) {
            e.consume();
          }
        }

        That's all there is. When this is executed in a browser, I can see all the text
        that is typed! I get better results if I use the keyPressed() routine, but I don't want to, as it may not be platform independent.

        Test Environment:
        =================
        I get this problem on:
          Windows NT4 (service pack 6) using IE5.5
        I have also tried it on the following environment, (and it didn't work):
          browser: Netscape Communicator 4.76
          OS: SunOS Release 5.6 Generic_105181-22
          machine: SUNW,Ultra-2; sparc; sun4u
          Window System: OpenWindows Version 3.6
        I have also tried it on the following environment, (and it didn't work):
          browser: Internet Explorer version 4
          platform: Windows 98

        But wait - just now I tried it on:
          Windows NT4 (service pack 6) using Netscape Communicator 4.5 and IT WORKS (i.e. I can't see any text as the user types)! It might therefore be a problem with Internet Explorer on NT?
        (Review ID: 115415)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                ehawkessunw Eric Hawkes (Inactive)
                Reporter:
                rlewis Roger Lewis (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: