setFont( new Font("TimesRoman",Font.BOLD,18) ); addKeyListener ( new KeyAdapter() { public void keyPressed( KeyEvent e ) { System.out.println(e); type( e.getKeyCode(), e.getKeyChar() ); } } ); requestFocus();
g.drawString(text.toString() + "_", 20, 20);
switch ( code ) { case ( KeyEvent.VK_BACK_SPACE ): if (text.length() > 0) text.setLength( text.length() - 1 ); break; case ( KeyEvent.VK_ENTER ): // eat text text.setLength( 0 ); break; default: if ( (ch >= ' ") && (ch <= '~") ) text.append( ch ); } repaint();