home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / ans / chap14 / exer1402 / Handle.java
Encoding:
Java Source  |  1997-04-20  |  1.2 KB  |  45 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class Handle extends Applet {
  5.    Canvas c;
  6.    TextField tf;
  7.    Panel p;
  8.  
  9.    public void init() {
  10.       c = new Canvas();
  11.       c.resize(50, 50);
  12.       c.setBackground(Color.blue);
  13.       add(c);
  14.  
  15.       p = new Panel();
  16.       p.setBackground(Color.red);
  17.       p.resize(50, 50);
  18.       add(p);
  19.  
  20.       tf = new TextField(10);
  21.       add(tf);
  22.    }
  23.  
  24.    public boolean handleEvent(Event e) {
  25.       System.out.println("\n --- " + e.target.getClass() + " ---");
  26.       if (e.target == p ||
  27.           e.target == tf ||
  28.           e.target == c)
  29.       {
  30.          System.out.println("arg is " + e.arg);
  31.          System.out.println("click count is " + e.clickCount);
  32.          System.out.println("evt is " + e.evt);
  33.          System.out.println("id is " + e.id);
  34.          System.out.println("key is " + e.key);
  35.          System.out.println("modifiers are " + e.modifiers);
  36.          System.out.println("target is " + e.target);
  37.          System.out.println("when is " + e.when);
  38.          System.out.println("x is " + e.x);
  39.          System.out.println("y is " + e.y);
  40.       }
  41.  
  42.       return super.handleEvent(e);
  43.    }
  44. }
  45.