Seite 38 |
Event Handling
|
EventObject |
ID |
Klasse |
ActionEvent |
ACTION_PERFORMED |
Button, List, Checkbox,MenuItem, TextField |
FocusEvent |
FOCUS_GAINED |
Component |
FOCUS_LOST |
||
KeyEvent |
KEY_PRESSED |
|
KEY_RELEASED |
||
KEY_TYPED |
||
MouseEvent |
MOUSE_ENTERED |
|
MOUSE_EXITED |
||
MOUSE_PRESSED |
||
MOUSE_RELEASED |
||
MOUSE_MOVED |
||
MOUSE_DRAGGED |
||
ComponentEvent |
COMPONENT_HIDDEN |
|
COMPONENT_SHOWN |
||
COMPONENT_MOVED |
||
COMPONENT_RESIZED |
||
ContainerEvent |
COMPONENT_ADDED |
Container |
COMPONENT_REMOVED |
||
ItemEvent |
SELECTED |
List, Choice, Checkbox |
DESELECTED |
CheckboxMenuItem |
|
ITEM_STATE_CHANGED |
||
AdjustmentEvent |
TRACK |
Scrollbar |
UNIT_INCREMENT |
||
UNIT_DECREMENT |
||
BLOCK_INCREMENT |
||
BLOCK_DECREMENT |
||
WindowEvent |
WINDOW_ACTIVATED |
Window, Frame, Dialog |
WINDOW_DEACTIVATED |
||
WINDOW_OPENED |
||
WINDOW_CLOSED |
||
WINDOW_ICONIFIED |
||
WINDOW_DEICONIFIED |
||
WINDOW_CLOSING |
||
TextEvent |
TEXT_VALUE_CHANGED |
TextComponent |
Funktionsweise des Event Handling:
Bem: java.awt.Component vererbt u.a. addMouseListener vergleiche hierzu Java 2 PLatform Specification java.awt / Component
import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class MouseListenerDemo extends Applet implements MouseListener { public void init() { setBackground(Color.blue); addMouseListener(this); } public void mouseClicked(MouseEvent e) { getAppletContext().showStatus( "click at x:"+e.getX()+" y:"+e.getY()); } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }
Ein solches Applet würde wie folgt aussehen:
vergleiche hierzu Java 2 PLatform Specification java.awt.event / MouseEventEin anderes Beispiel: hier ActionListener anstatt MouseListener
import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class ActionApplet extends Applet implements ActionListener { private Button b; public ActionFrame() { b = new Button("Java"); b.addActionListener(this); add("Center",b); } public void actionPerformed(ActionEvent e) { System.out.println("Action in Button Java"); } }