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

4032657 - Canvas Doesn't receive Key Events (1.1.x only)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.3, 1.1.8
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      solaris_2.6, windows_nt

      Description



      Name: rlT66838 Date: 07/21/97


      Java People,

      After 8 hours of fiddling, I've reproduced a bug in the Java Bug fixes!
      Specifically: 4032657. This email is to help anyone else with the problem and
      maybe to help sun identify and fix the problem!

      (If you've never looked:
      http://java.sun.com/products/jdk/1.1/knownbugs/classes_awt.html
      )

      The bug is, I've created a frame with a Canvas on it. The canvas is a
      keyListener. It prints out all the key events. (See code below).

      By experimentation I've found:

      A) a Frame with a Canvas works fine. All key events received.
      B) a frame with a border layout, the Canvas in the center, and
         a button to the North, works fine too. All key events received.
      C) BUT IF YOU ADD A PANEL in the North, with the button in the panel,
         the canvas DOES NOT RECEIVE any key events!

      In fact. If you just add the panel, and not the button, it doesn't receive
      either. But I can't prove the location without something showing me where the
      edge is.

      BTW. The mouse events are not a problem. They are always received correctly.

      BTW 2. Adding a Panel between the canvas and the frame is no improvement.

      This makes some of my work pretty useless. Can't do much here!

      Regards,

      Larry


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

      public class TestCanvas extends Frame
         implements KeyListener, MouseListener {
        public TestCanvas(String s)
        {
           super(s);
           this.setLayout(new BorderLayout(0,0));

           // comment out the next 6 lines and the keytyped works
           // fine. Let them stay and the canvas never gets the events. Nor
           // does this Frame. But the button works! :-}
           Panel p = new Panel();
           p.addKeyListener(this);
           p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15));
           Button
           wquit = new Button("Quit");
           p.add(wquit);
           this.add("North", p);

           TestSubCanvas c=new TestSubCanvas();
           this.add("Center", c);
           c.addKeyListener(this);
           c.addMouseListener(this);
         }
        public void keyTyped(KeyEvent _e)
           { println("TestCanvas.keyTyped"); }
        public void keyPressed(KeyEvent _e)
           { println("TestCanvas.keyPressed"); }
        public void keyReleased(KeyEvent _e)
           { println("TestCanvas.keyReleased");}
        public void mouseClicked(MouseEvent _e)
          { println("TestCanvas.mouseClicked");}
        public void mouseEntered(MouseEvent _e)
           { println("TestCanvas.mouseEntered"); }
        public void mouseExited(MouseEvent _e)
          { println("TestCanvas.mouseExited");}
        public void mousePressed(MouseEvent _e)
          { println("TestCanvas.mousePressed");}
        public void mouseReleased(MouseEvent _e)
          { println("TestCanvas.mouseReleased");}
        public static void main(String argv[])
        {
          Frame f = new TestCanvas("Test Canvas");
          f.show();
        }
        public void println(String s)
        {
          System.out.println(s);
        }
      } // TestCanvas
      class TestSubCanvas extends Canvas
         implements KeyListener, MouseListener {
        public TestSubCanvas()
        {
          super();
          this.addKeyListener(this);
          this.addMouseListener(this);
        }
        public void keyTyped(KeyEvent _e)
           { println("TestSubCanvas.keyTyped"); }
        public void keyPressed(KeyEvent _e)
           { println("TestSubCanvas.keyPressed"); }
        public void keyReleased(KeyEvent _e)
           { println("TestSubCanvas.keyReleased");}
        public void mouseClicked(MouseEvent _e)
          { println("TestSubCanvas.mouseClicked");}
        public void mouseEntered(MouseEvent _e)
           { println("TestSubCanvas.mouseEntered"); }
        public void mouseExited(MouseEvent _e)
          { println("TestSubCanvas.mouseExited");}
        public void mousePressed(MouseEvent _e)
          { println("TestSubCanvas.mousePressed");}
        public void mouseReleased(MouseEvent _e)
          { println("TestSubCanvas.mouseReleased");}

        public void println(String s)
        { System.out.println(s);
        }
      } // TestSubCanvas



      ======================================================================

        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: