javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
1.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Jan 21 07:00:56 2013 +0100
1.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Jan 21 13:43:40 2013 +0100
1.3 @@ -36,37 +36,39 @@
1.4 @Property(name = "hover", type = boolean.class)
1.5 })
1.6 public class App {
1.7 + private static final Calculator CALC = new Calculator().applyBindings();
1.8 +
1.9 @On(event = CLICK, id="clear")
1.10 static void clear() {
1.11 - Calculator.setMemory(0);
1.12 - Calculator.setOperation(null);
1.13 - Calculator.setDisplay(0);
1.14 + CALC.setMemory(0);
1.15 + CALC.setOperation(null);
1.16 + CALC.setDisplay(0);
1.17 }
1.18
1.19 @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
1.20 static void applyOp(String op) {
1.21 - Calculator.setMemory(Calculator.getDisplay());
1.22 - Calculator.setOperation(op);
1.23 - Calculator.setDisplay(0);
1.24 + CALC.setMemory(CALC.getDisplay());
1.25 + CALC.setOperation(op);
1.26 + CALC.setDisplay(0);
1.27 }
1.28
1.29 @On(event = MOUSE_OVER, id= { "result" })
1.30 static void attemptingIn(String op) {
1.31 - Calculator.setHover(true);
1.32 + CALC.setHover(true);
1.33 }
1.34 @On(event = MOUSE_OUT, id= { "result" })
1.35 static void attemptingOut(String op) {
1.36 - Calculator.setHover(false);
1.37 + CALC.setHover(false);
1.38 }
1.39
1.40 @On(event = CLICK, id="result")
1.41 static void computeTheValue() {
1.42 - Calculator.setDisplay(compute(
1.43 - Calculator.getOperation(),
1.44 - Calculator.getMemory(),
1.45 - Calculator.getDisplay()
1.46 + CALC.setDisplay(compute(
1.47 + CALC.getOperation(),
1.48 + CALC.getMemory(),
1.49 + CALC.getDisplay()
1.50 ));
1.51 - Calculator.setMemory(0);
1.52 + CALC.setMemory(0);
1.53 }
1.54
1.55 private static double compute(String op, double memory, double display) {
1.56 @@ -83,16 +85,16 @@
1.57 static void addDigit(String digit) {
1.58 digit = digit.substring(1);
1.59
1.60 - double v = Calculator.getDisplay();
1.61 + double v = CALC.getDisplay();
1.62 if (v == 0.0) {
1.63 - Calculator.setDisplay(Integer.parseInt(digit));
1.64 + CALC.setDisplay(Integer.parseInt(digit));
1.65 } else {
1.66 String txt = Double.toString(v);
1.67 if (txt.endsWith(".0")) {
1.68 txt = txt.substring(0, txt.length() - 2);
1.69 }
1.70 txt = txt + digit;
1.71 - Calculator.setDisplay(Double.parseDouble(txt));
1.72 + CALC.setDisplay(Double.parseDouble(txt));
1.73 }
1.74 }
1.75
1.76 @@ -105,8 +107,4 @@
1.77 }
1.78 return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
1.79 }
1.80 -
1.81 - static {
1.82 - Calculator.applyBindings();
1.83 - }
1.84 }