Article ID: 188808
Article Last Modified on 7/15/2004
import java.awt.*;
// To see JDK 1.1-style events, uncomment this line.
// import java.awt.event.*;
public class Testevent
{
public static void main(String args[])
{
Frame f=new Frame();
f.setLayout(new java.awt.BorderLayout());
TextArea ta = new TextAreaEvents();
f.add("Center", ta);
f.setSize(320,200);
f.setVisible(true);
// To see JDK 1.1-style events, uncomment this line.
// To see JDK 1.02-style events, leave it out.
// ta.addKeyListener(new TestKeyListener());
}
}
class TextAreaEvents extends TextArea
{
public boolean handleEvent(Event e)
{
System.out.println(e);
System.out.print(e.id==Event.KEY_PRESS? "KEY_PRESS":"");
System.out.print(e.id==Event.KEY_RELEASE? "KEY_RELEASE":"");
System.out.print(e.id==Event.KEY_ACTION? "KEY_ACTION":"");
System.out.print(e.id==Event.KEY_ACTION_RELEASE?
"KEY_ACTION_RELEASE":"");
System.out.println();
return super.handleEvent(e);
}
}
// To see JDK 1.1-style events uncomment the following class:
/*
class TestKeyListener implements KeyListener
{
public void keyPressed(KeyEvent e)
{
System.out.println("Listener -- pressed: "+e);
}
public void keyTyped(KeyEvent e)
{
System.out.println("Listener -- typed: "+e);
}
public void keyReleased(KeyEvent e)
{
System.out.println("Listener -- released: "+e);
}
}
/* End of block. */
Button SPACE, ENTER Choice SPACE, ENTER, HOME, END, PGUP, PGDOWN, ARROWUP, ARROWLEFT, ARROWRIGHT, ARROWDOWN Checkbox SPACE, ENTER List SPACE, ENTER, HOME, END, PGUP, PGDOWN, ARROWUP, ARROWLEFT, ARROWRIGHT, ARROWDOWN TextArea TAB, PGUP, PGDOWN
Additional query words: tab key-pressed event textarea Component
Keywords: kbbug kbpending KB188808