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

Canvas does not pass on KeyEvent's.

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: tb29552 Date: 09/30/98


      The following code HALF works in 1.1.6: It prints out
      Typed events, but not Pressed events.

      With 1.1.7, however, NO key events seem to come
      through.

      Interestingly, if you comment out the block in
      the constructor that adds the Canvas widget, it
      works fine.

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

      class jtest extends Frame implements KeyListener, MouseListener {

              Canvas dummy;

              static void print(String msg){ System.out.println(msg);}

              public void mouseEntered(MouseEvent evt) {
                      print("asking for focus");
                      requestFocus();
              }
              public void mouseExited(MouseEvent evt) {}
              public void mouseClicked(MouseEvent evt) {}
              public void mousePressed(MouseEvent evt) {}
              public void mouseReleased(MouseEvent evt) {}

              public void keyPressed(KeyEvent evt) {
                      print("Pressed: "+evt.getKeyChar());
              }
              public void keyTyped(KeyEvent evt) {
                      print("Typed: "+evt.getKeyChar());
              }
              public void keyReleased(KeyEvent evt) {}

              public jtest(){
                      setTitle("test frame");

                      dummy=new Canvas();
                      add(new Canvas());
                      dummy.setSize(300,300);
                      dummy.addKeyListener(this);
                      dummy.addMouseListener(this);

                      setSize(300,300);

                      addKeyListener(this);
                      addMouseListener(this);

              }
              public static void main(String args[]){
                      jtest top = new jtest();
                      top.setVisible(true);
                      print("Press a key in the window");
              }
      }
      (Review ID: 39628)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rkhansunw Robi Khan (Inactive)
                Reporter:
                tbell Tim Bell
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: