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

KeyEvents from JPanels - work on Windows NT, not in Solaris

XMLWordPrintable

    • x86
    • solaris_2.5.1



      Name: sk89920 Date: 08/09/99


      I want to generate KeyEvents from a JPanel. I have tried the
      following code (taken in part from the CoreJava Volume1 -
      Fundamentals - 1.2 edition - chapter 8 page 341), which does
      override the isFocusTraversable method to return 'true' for the
      panel.

      I compiled this code under Solaris (details as in section 5)
      but it doesn't work. However, the Solaris-compiled code does
      work on Windows NT (Pentium II).

      Why is there a difference and is there a workround?



      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      class SketchPanel extends JPanel implements KeyListener {
      public SketchPanel() {
      addKeyListener(this);
      }

      public void keyPressed(KeyEvent evt) {
      System.out.println("SSSSS");
      int keyCode = evt.getKeyCode();
      int modifiers = evt.getModifiers();
      System.out.println(keyCode);
      System.out.println(modifiers);
      }

      public void keyReleased(KeyEvent evt) {}

      public void keyTyped(KeyEvent evt) {}

      public boolean isFocusTraversable() {
      return true;
      }

      }

      class SketchFrame extends JFrame {
      public SketchFrame() {
      setTitle("Test");
      setSize(300,200);
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      } );

      Container contentPane = getContentPane();
      contentPane.add(new SketchPanel());
      }
      }

      public class Sketch {
      public static void main(String[] args) {
      SketchFrame frame = new SketchFrame();
      frame.show();
      }
      }
      (Review ID: 93683)
      ======================================================================

            dmikhalksunw Denis Mikhalkin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: