FileDocCategorySizeDatePackage
KeyWatcher.javaAPI DocExample842Wed Feb 19 01:29:50 GMT 1997None

KeyWatcher

public class KeyWatcher extends Applet

Fields Summary
StringBuffer
text
Constructors Summary
Methods Summary
public voidinit()


	    
		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();
	
public voidpaint(java.awt.Graphics g)

		g.drawString(text.toString() + "_", 20, 20);
	
public voidtype(int code, char ch)

		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();