Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jlib/EventFrame.java


1   package jlib;
2   
3   import java.awt.*;
4   import silk.*;
5   
6   
7   /**
8    *  This class represents a Frame in which the window
9    *  which responds "properly" to window closing events.
10   *  It also allows one to handle events in the Frame by
11   *  specifying callbacks using Scheme closures.
12   *
13   *  This is needed when working with the Java 1.0 event
14   *  model which does not have event listeners.
15   *
16   *  @author Timothy J. Hickey, tim@cs.brandeis.edu http://www.cs.brandeis.edu/~tim 
17   */
18  
19  
20  public class EventFrame extends java.awt.Frame {
21  
22      public Procedure handler;
23  
24      public EventFrame() {
25    super();
26      }
27  
28      public EventFrame(String title) {
29    super(title);
30      }
31  
32    public void addEventHandler(Procedure callback) {
33       handler = callback;
34    }
35  
36    public void update(Graphics g) {
37      paint(g);
38    }
39  
40    public boolean handleEvent(Event e) {
41  
42      if (handler != null) {
43         return (null != handler.apply(U.list(e)));
44      }
45      else if (e.id==Event.WINDOW_DESTROY) {
46         hide(); dispose(); return true;
47      }
48      else return super.handleEvent(e);
49    }
50  }
51