-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestGUI.recaf
60 lines (49 loc) · 1.27 KB
/
TestGUI.recaf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package generated;
import recaf.demo.direct.GUI;
import recaf.demo.direct.GUI.Render;
import recaf.demo.direct.GUI.Handle;
import java.util.stream.IntStream;
import java.util.Iterator;
import java.io.StringWriter;
public class TestGUI {
private recaf GUI alg;
public TestGUI(GUI alg) {
this.alg = alg;
}
recaf void h2(String title) {
tag ("h2") {
echo! title;
}
}
static Iterable<Integer> range(int n) {
return new Iterable<Integer>() {
public Iterator<Integer> iterator() {
return IntStream.range(0, n).iterator();
}
};
}
static void println(String x) {
System.out.println(x);
}
static
void hello(recaf GUI alg, int n) {
tag ("div")
for (int i: range(n))
tag ("p") {
echo! "Hello world " + i + "!\n";
button ("Click " + i)
if (i % 2 == 0) println("even " + i);
else println("odd " + i);
}
}
static void sendToServer(String x) {
System.out.println(x);
}
public static void main(String args[]) {
StringWriter w = new StringWriter();
hello(new Render(w), 10);
sendToServer(w.toString());
// ... receive the clicked id; assume it's "id2"
hello(new Handle("id2"), 10); // prints out even 2
}
}