javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
1 package org.apidesign.bck2brwsr.mavenhtml;
3 import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
4 import org.apidesign.bck2brwsr.htmlpage.api.Page;
6 @Page(xhtml="Calculator.xhtml")
8 private static final int OP_PLUS = 1;
9 private static final int OP_MINUS = 2;
10 private static final int OP_MUL = 3;
11 private static final int OP_DIV = 4;
13 static double memory = 0;
14 static int operation = 0;
23 private static void setValue(double v) {
24 StringBuilder sb = new StringBuilder();
26 Calculator.DISPLAY.setValue(sb.toString());
29 private static double getValue() {
30 return Double.parseDouble(Calculator.DISPLAY.getValue());
55 static void computeTheValue() {
58 case OP_PLUS: setValue(memory + getValue()); break;
59 case OP_MINUS: setValue(memory - getValue()); break;
60 case OP_MUL: setValue(memory * getValue()); break;
64 @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
65 static void addDigit(String digit) {
66 digit = digit.substring(1);
67 String v = Calculator.DISPLAY.getValue();
68 if ("0".equals(v) || v == null) {
69 Calculator.DISPLAY.setValue(digit);
71 Calculator.DISPLAY.setValue(v + digit);