1
import org.jcsp.lang.*;
2
import org.jcsp.util.*;
3
import org.jcsp.plugNplay.*;
5
public class FramedButtonGridExample {
7
public static void main (String argv[]) {
9
// labels for the grid of buttons
11
final String[][] label = {
12
new String[] {"Java", "occam-pi", "Handel-C"},
13
new String[] {"C", "C++", "C#"},
14
new String[] {"Haskell", "Modula", "Goodbye World"}
17
final int nDown = label.length;
18
final int nAcross = label[0].length;
20
// initial pixel sizes for the frame for the grid of buttons
22
final int pixDown = 20 + (nDown*100);
23
final int pixAcross = nAcross*120;
25
// all button events are wired (for this example) to the same channel ...
27
final Any2OneChannel allEvents =
28
Channel.any2one (new OverWriteOldestBuffer (10));
30
final Any2OneChannel[][] event = new Any2OneChannel[nDown][nAcross];
32
for (int i = 0; i < nDown; i++) {
33
for (int j = 0; j < nAcross; j++) {
34
event[i][j] = allEvents;
38
// make the grid of buttons (each one separately configured) ...
40
final One2OneChannel[][] configure = new One2OneChannel[nDown][nAcross];
42
for (int i = 0; i < nDown; i++) {
43
configure[i] = Channel.one2oneArray (nAcross);
46
final ChannelInput[][] configureIn = new ChannelInput[nDown][nAcross];
47
final ChannelOutput[][] eventOut = new ChannelOutput[nDown][nAcross];
49
for (int i = 0; i < nDown; i++) {
50
configureIn[i] = Channel.getInputArray (configure[i]);
51
eventOut[i] = Channel.getOutputArray (event[i]);
54
final FramedButtonGrid grid =
55
new FramedButtonGrid (
56
"FramedButtonGrid Demo", nDown, nAcross,
57
pixDown, pixAcross, configureIn, eventOut
72
for (int i = 0; i < nDown; i++) {
73
for (int j = 0; j < nAcross; j++) {
74
configure[i][j].out ().write (label[i][j]);
78
boolean running = true;
80
final String s = (String) allEvents.in ().read ();
81
System.out.println ("Button `" + s + "' pressed ...");
82
running = (s != label[nDown - 1][nAcross - 1]);