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

Panel does not accept keys from Japanes Keyboard 106 (on PC)

XMLWordPrintable

    • 1.1.4
    • x86, sparc
    • generic, solaris_2.5, windows_95, windows_nt
    • Verified

      System: Windows NT4.0 Running under Japanese locale, With Japanes 106 Keyboard

      To reporduce:

      1. Compile the attached program PanelTest and run it
      2. Type Shift+2, instead of getting character " (double quote) gets character @
      3. Type Shift+9 instead of getting character ) (close brace) gets ( open braces

      Layout follows keys defined US-101 ASCII Keyboard layout


      ==== neil.smithline@Eng 1997-06-20

      The attached two java files listen for keyboard events and print the
      revceived key sequences. The difference is PanelTest is with 1.0 event
      model and CanvasEditor with 1.1 model. CanvasEditor works with Japanese
      keyboard with JDK1.1.1 where as PanelTest doesn't work with Japanese keyboard.

      --Brood_of_Chickens_717_000
      Content-Type: TEXT/plain; name="PanelTest.java"; charset=US-ASCII; x-unix-mode^F66
      Content-Transfer-Encoding: QUOTED-PRINTABLE
      Content-Description: PanelTest.java
      Content-MD5: nk+YdwTV4jKjyS+Mh0QMXA==

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

      class KCommand implements KeyListener {
          public void keyReleased (KeyEvent k) {
      ;
          }
          
          public void keyTyped (KeyEvent k) {
      ;
          }

          public void keyPressed (KeyEvent k) {
      String str = null;
      int keycode = k.getKeyCode();

      switch(keycode) {
      case KeyEvent.VK_TAB:
      str = "TAB";
      break;
      case KeyEvent.VK_ESCAPE:
      str = "ESC";
      break;
      case KeyEvent.VK_BACK_SPACE:
      str = "BKSP";
      break;
      case KeyEvent.VK_DELETE:
      str = "DEL";
      break;
      default:
      break;
      }
      System.out.println(str);
      System.out.println("Keycode: " + keycode);
      System.out.println("Keycode & 0xff: " + (keycode & 0xff));
      System.out.println("Keychar: " + k.getKeyChar());
      return;
          }
      }

      public class PanelTest extends Panel {
          private static final int TAB = 9;
          private static final int LF = 10;
          private static final int CR = 13;
          private static final int ESC = 27;
          private static final int BKSP = '\b';
          private static final int DEL = 127;

          public PanelTest() {
      this.enableEvents(AWTEvent.KEY_EVENT_MASK);
      this.addKeyListener(new KCommand());
          }

          public boolean keyDown(Event evt, int keycode) {
      String str = null;
      switch(keycode & 0xff) {
      case TAB:
      str = "TAB";
      break;
      case ESC:
      str = "ESC";
      break;
      case BKSP:
      str = "BKSP";
      break;
      case DEL:
      str = "DEL";
      break;
      default:
      break;
      }
      System.out.println(str);
      System.out.println("Keycode: " + keycode);
      System.out.println("Keycode & 0xff: " + (keycode & 0xff));
      return false;
          }
          public static void main(String [] args) {
      Frame f = new Frame();
      PanelTest panel = new PanelTest();
      f.add (panel);
      f.setSize(200, 200);
      f.show();
          }
      }

      --Brood_of_Chickens_717_000
      Content-Type: TEXT/plain; name="CanvasEditor.java"; charset=us-ascii; x-unix-mode^F66
      Content-Description: CanvasEditor.java
      Content-MD5: o5MrpLE1vB5Efy2EWI6CHw==

      import java.awt.*;
      import java.util.Locale;
      import java.util.Date;
      import java.awt.event.*;

      /** Extends Panel to input non-ascii characters */
      public class CanvasEditor extends Panel
      {
        //private TextField textf;
        private int max_line_number,cl;
        private StringBuffer lines[];

        
        public CanvasEditor () {
          super (new BorderLayout ());
          cl= 0;
          max_line_number = 1024;
          lines = new StringBuffer [max_line_number];
          for (int i =0; i< max_line_number; i++)
            lines[i] = new StringBuffer();
          //textf = new TextField ( );
          //add (textf,"South");
          //textf.setVisible (false);
          enableEvents(AWTEvent.KEY_EVENT_MASK );
        // textf.addKeyListener ( this );
         // textf.addTextListener ( this );
        }


         public void processKeyEvent ( KeyEvent fe ) {
           /*
             KeyEvent kk;
             kk = new KeyEvent (textf, fe.getID(), new Date().getTime(),
             fe.getModifiers(),fe.getKeyCode(),
             fe.getKeyChar());
           EventQueue.getEventQueue().postEvent ( kk );
           */
           if (fe.getID() == KeyEvent.KEY_TYPED) {
               addKey (fe);
      return;
           }
           if (fe.getID() == KeyEvent.KEY_RELEASED)
             return;
           
           if (fe.getID() != KeyEvent.KEY_PRESSED)
             return;

           int k = fe.getKeyCode();
           if (k == KeyEvent.VK_A) {
             if (fe.getModifiers() == KeyEvent.CTRL_MASK) {
      System.out.println ("Conversion ON !!");
      //ftextf.setVisible (true);
      doLayout();
      // textf.requestFocus ();
             }
           }
           if (k == KeyEvent. VK_ENTER) {
             cl++;
             if (cl > max_line_number) {
      StringBuffer lbuf[];
      lbuf = new StringBuffer [max_line_number + 5];
      for (int i = 0; i < max_line_number; i++) {
      lbuf[i] = lines[i];
      }
      for (int i =0; i< max_line_number; i++)
      lbuf[max_line_number+i] = new StringBuffer ();
      max_line_number+=5;
      lines = lbuf;
             }
           }
           // System.out.println ("processKeyEvent"+fe);
         }

        public void paint () {
          paint (getGraphics());
        }


        public void paint (Graphics g) {
          int i;
          FontMetrics fm = g.getFontMetrics ();
          int ht = fm . getHeight();
          int txt_y = 0;
          for (i=0; i< max_line_number; i++) {
            txt_y += ht;
            g.drawString (new String (lines[i]),0,txt_y);
          }
        }
        
        public void clearBuffer () {
          for (int i =0; i<cl;i++)
            lines[i].setLength(0);
          cl = 0;
          paint();
        }


        public static void main (String[] args) {
          Locale mylocale = Locale.getDefault();
          Frame f = new Frame();
          CanvasEditor it = new CanvasEditor ();
          f.add (it);
          f.setSize (200,200);
          f.show();
        }

        private void addKey ( KeyEvent k ) {
          lines [cl].append ( k . getKeyChar());
          paint (getGraphics());
      }
      }

      --Brood_of_Chickens_717_000--

            joconnersunw John Oconner (Inactive)
            ssenthilsunw Shanmugam Senthil (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: