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