FileDocCategorySizeDatePackage
EventTester1.javaAPI DocExample5051Mon Sep 22 13:30:30 BST 1997None

EventTester1

public class EventTester1 extends Applet
An applet that gives details about Java 1.0 events

Fields Summary
protected Vector
lines
A list of lines to display in the window
Constructors Summary
Methods Summary
private java.lang.Stringfunction_key_name(int key)

    switch(key) {
      case Event.HOME: return "Home";     case Event.END: return "End";
      case Event.PGUP: return "Page Up";  case Event.PGDN: return "Page Down";
      case Event.UP: return "Up";         case Event.DOWN: return "Down";
      case Event.LEFT: return "Left";     case Event.RIGHT: return "Right";
      case Event.F1: return "F1";         case Event.F2: return "F2";
      case Event.F3: return "F3";         case Event.F4: return "F4";
      case Event.F5: return "F5";         case Event.F6: return "F6";
      case Event.F7: return "F7";         case Event.F8: return "F8";
      case Event.F9: return "F9";         case Event.F10: return "F10";
      case Event.F11: return "F11";       case Event.F12: return "F12";
    }
    return "Unknown Function Key";
  
public booleangotFocus(java.awt.Event e, java.lang.Object what)

    showLine("Got Focus"); return true;
  
public booleankeyDown(java.awt.Event e, int key)

    int flags = e.modifiers;
    if (e.id == Event.KEY_PRESS)                 // a regular key
      showLine("Key Down: " + mods(flags) + key_name(e));
    else if (e.id == Event.KEY_ACTION)           // a function key
      showLine("Function Key Down: " + mods(flags) + function_key_name(key));
    return true;
  
public booleankeyUp(java.awt.Event e, int key)

    int flags = e.modifiers;
    if (e.id == Event.KEY_RELEASE)               // a regular key
      showLine("Key Up: " + mods(flags) + key_name(e));
    else if (e.id == Event.KEY_ACTION_RELEASE)   // a function key
      showLine("Function Key Up: " + mods(flags) + function_key_name(key));
    return true;
  
private java.lang.Stringkey_name(java.awt.Event e)

    char c = (char) e.key;
    if (e.controlDown()) {    // If CTRL flag is set, handle control chars.
      if (c < ' ") {
        c += '@";
        return "^" + c;
      }
    }
    else {                    // If CTRL flag is not set, then certain ASCII
      switch (c) {            // control characters have special meaning.
        case '\n": return "Return";
        case '\t": return "Tab";
        case '\033": return "Escape";
        case '\010": return "Backspace";
      }
    }
    // Handle the remaining possibilities.
    if (c == '\177") return "Delete";
    else if (c == ' ") return "Space";
    else return String.valueOf(c);
  
public booleanlostFocus(java.awt.Event e, java.lang.Object what)

    showLine("Lost Focus"); return true;
  
private java.lang.Stringmods(int flags)

    String s = "[ ";
    if (flags == 0) return "";
    if ((flags & Event.SHIFT_MASK) != 0) s += "Shift ";
    if ((flags & Event.CTRL_MASK) != 0) s += "Control ";
    if ((flags & Event.META_MASK) != 0) s += "Meta ";
    if ((flags & Event.ALT_MASK) != 0) s += "Alt ";
    s += "] ";
    return s;
  
public booleanmouseDown(java.awt.Event e, int x, int y)

    showLine(mods(e.modifiers) +  "Mouse Down: [" + x + "," + y + "]");
    return true;
  
public booleanmouseDrag(java.awt.Event e, int x, int y)

    showLine(mods(e.modifiers) + "Mouse Drag: [" + x + "," + y + "]");
    return true;
  
public booleanmouseEnter(java.awt.Event e, int x, int y)

    showLine("Mouse Enter: [" + x + "," + y + "]"); return true;
  
public booleanmouseExit(java.awt.Event e, int x, int y)

    showLine("Mouse Exit: [" + x + "," + y + "]"); return true;
  
public booleanmouseMove(java.awt.Event e, int x, int y)

    showLine(mods(e.modifiers) + "Mouse Move: [" + x + "," + y + "]");
    return true;
  
public booleanmouseUp(java.awt.Event e, int x, int y)

    showLine(mods(e.modifiers) + "Mouse Up: [" + x + "," + y + "]");
    return true;
  
public voidpaint(java.awt.Graphics g)
This method repaints the text in the window

    for(int i = 0; i < lines.size(); i++)
      g.drawString((String)lines.elementAt(i), 20, i*16 + 50);
  
protected voidshowLine(java.lang.String s)
Add a new line to the list of lines, and redisplay

              
      
    if (lines.size() == 20) lines.removeElementAt(0);
    lines.addElement(s);
    repaint();