All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.ActionEventHandler
____________________ | | event | ActionEventHandler |--->--- |____________________|
The ActionEventHandler class implements the ActionListener interface and can be used for any component which allows the addition of ActionListeners. When the component is created a new instance of the ActionEventHandler should be created and added as an ActionListener to the component. The process must be set running (either asynchronously using ProcessNetwork or as part of a Parallel construct).
The main body of this process waits to be notified by a component invoking the actionPerformed() method. The process then wakes up and sends the String representing the Action down the event Channel. Any further calls to actionPerformed() while the process is writing will be discarded so as not to block the main Java event Thread. When another process reads from the Channel this process loops round and waits to be notified again.
Input Channels | ||
---|---|---|
Output Channels | ||
event | String | The string representing the ActionEvent from the component that generated the event. |
import java.awt.*; import jcsp.lang.*; import jcsp.awt.event.*; public class ChannelButton extends Button implements CSProcess { private ActionEventHanlder handler; public ChannelButton(ChannelOutput event, String label) { super(s); if (event !=null) { handler = new ActionEventHandler(event); addActionListener(handler); } } public void run() { if (handler != null) { handler.run(); } } }NOTE: This is in fact how the ActiveButton and ActiveMenuItem classes are implemented. Except they include an extra CSProcess and Channel for configuring the Component.
import java.awt.*; import jcsp.awt.event.*; import jcsp.lang.*; : : { final Channel event = new One2OneChannel(); Button button = new Button("Active"); add(button); ActionEventHandler handler = new ActionEventHandler(event); button.addActionListener(handler); new Parallel(new CSProcess[] { button, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out.println("Button '" + o + "' Pressed"); } } } }).run(); } }
public ActionEventHandler(ChannelOutput event)
public void actionPerformed(ActionEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index