public void dispatchEvent(AWTEvent event){
  if (!(event instanceof KeyEvent)) {
    return;
  }
  KeyEvent e=(KeyEvent)event;
  int eventID=event.getID();
  boolean notInCompositionMode=buffer.length() == 0;
  if (eventID == KeyEvent.KEY_PRESSED) {
    if (notInCompositionMode) {
      return;
    }
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
      moveCaretLeft();
    break;
case KeyEvent.VK_RIGHT:
  moveCaretRight();
break;
}
}
 else if (eventID == KeyEvent.KEY_TYPED) {
char c=e.getKeyChar();
if (notInCompositionMode) {
if (c != '\\') {
return;
}
startComposition();
}
 else {
switch (c) {
case ' ':
finishComposition();
break;
case '\u007f':
deleteCharacter();
break;
case '\b':
deletePreviousCharacter();
break;
case '\u001b':
cancelComposition();
break;
case '\n':
case '\t':
sendCommittedText();
break;
default :
composeUnicodeEscape(c);
break;
}
}
}
 else {
if (notInCompositionMode) {
return;
}
}
e.consume();
}

public void dispatchEvent ( AWTEvent event ) { if ( ! ( event instanceof KeyEvent ) ) { return ; } KeyEvent e = ( KeyEvent ) event ; int eventID = event . getID ( ) ; boolean notInCompositionMode = buffer . length ( ) == 0 ; if ( eventID == KeyEvent . KEY_PRESSED ) { if ( notInCompositionMode ) { return ; } switch ( e . getKeyCode ( ) ) { case KeyEvent . VK_LEFT : moveCaretLeft ( ) ; break ; case KeyEvent . VK_RIGHT : moveCaretRight ( ) ; break ; } } else if ( eventID == KeyEvent . KEY_TYPED ) { char c = e . getKeyChar ( ) ; if ( notInCompositionMode ) { if ( c != '\\' ) { return ; } startComposition ( ) ; } else { switch ( c ) { case ' ' : finishComposition ( ) ; break ; case '' : deleteCharacter ( ) ; break ; case '\b' : deletePreviousCharacter ( ) ; break ; case '' : cancelComposition ( ) ; break ; case '\n' : case '\t' : sendCommittedText ( ) ; break ; default : composeUnicodeEscape ( c ) ; break ; } } } else { if ( notInCompositionMode ) { return ; } } e . consume ( ) ; }
this is the input method ' s main routine . the composed text is stored in buffer .
