/* TclButton.java: a button that makes Tcl call-backs * * Copyright (c) 1998 The Regents of the University of California. * All Rights Reserved. See the COPYRIGHT file for details. */ package tutorial.tcltk98; import tcl.lang.*; import java.awt.*; import java.awt.event.*; public class TclButton extends java.awt.Button { Interp tclInterp; String tclScript; int count = 5; public TclButton (Interp interp) { super("Push me!"); tclInterp = interp; addActionListener(new LocalListener()); } public void setScript (String script) { tclScript = script; } class LocalListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (--count == 0) { count = 5; Notifier n = tclInterp.getNotifier(); TclEvent t = new EvalEvent(); n.queueEvent(t,TCL.QUEUE_TAIL); t.sync(); } } } class EvalEvent extends TclEvent { public int processEvent (int flags) { try { tclInterp.eval(tclScript); } catch (Exception x) {} return 1; } } }