JDK-4053800 : Panel does not accept keys from Japanes Keyboard 106 (on PC)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.0,2.0,dev5,1.1.1
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_2.5,windows_95,windows_nt generic,solaris_2.5,windows_95,windows_nt
  • CPU: x86,sparc
  • Submitted: 1997-05-22
  • Updated: 2016-05-17
  • Resolved: 1997-09-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.1.4 1.1.4Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
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--


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.1.4 FIXED IN: 1.1.4 INTEGRATED IN: 1.1.4 VERIFIED IN: 1.1.4
20-08-2004

EVALUATION Problem is in awt_Component.cpp. WindowsKeyToJavaChar is one of the culprits. Will replace the hardcoded tables with calls to Win32 API to get proper mappings, shift state, etc. [joconner 7/7/97] Trying to get code review and some AWT knowledge to confirm potential fixes.
20-08-2004

SUGGESTED FIX Don't hardcode key tables. Use Win32 API to convert virtual keys to chars and vice versa.
20-08-2004

PUBLIC COMMENTS Fixed in upcoming Sparkler release.
20-08-2004