diff options
Diffstat (limited to 'src/com/vaadin/demo/Calc.java')
-rw-r--r-- | src/com/vaadin/demo/Calc.java | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/com/vaadin/demo/Calc.java b/src/com/vaadin/demo/Calc.java deleted file mode 100644 index d2a0d3e25a..0000000000 --- a/src/com/vaadin/demo/Calc.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.vaadin.demo; - -import com.vaadin.ui.Button; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Window; - -// Calculator is created by extending Application-class. Application is -// deployed by adding ApplicationServlet to web.xml and this class as -// "application" parameter to the servlet. -@SuppressWarnings("serial") -public class Calc extends com.vaadin.Application { - - // Calculation data model is automatically stored in the user session - private double current = 0.0; - private double stored = 0.0; - private char lastOperationRequested = 'C'; - - // User interface components - private final Label display = new Label("0.0"); - private final GridLayout layout = new GridLayout(4, 5); - - // Application initialization creates UI and connects it to business logic - @Override - public void init() { - - // Place the layout to the browser main window - setMainWindow(new Window("Calculator Application", layout)); - - // Create and add the components to the layout - layout.addComponent(display, 0, 0, 3, 0); - for (String caption : new String[] { "7", "8", "9", "/", "4", "5", "6", - "*", "1", "2", "3", "-", "0", "=", "C", "+" }) { - Button button = new Button(caption, new Button.ClickListener() { - public void buttonClick(Button.ClickEvent event) { - - // On button click, calculate and show the result - display.setValue(calculate(event.getButton())); - } - }); - layout.addComponent(button); - } - } - - // Calculator "business logic" implemented here to keep the example minimal - private double calculate(Button buttonClicked) { - char requestedOperation = buttonClicked.getCaption().charAt(0); - if ('0' <= requestedOperation && requestedOperation <= '9') { - current = current * 10 - + Double.parseDouble("" + requestedOperation); - return current; - } - switch (lastOperationRequested) { - case '+': - stored += current; - break; - case '-': - stored -= current; - break; - case '/': - stored /= current; - break; - case '*': - stored *= current; - break; - case 'C': - stored = current; - break; - } - lastOperationRequested = requestedOperation; - current = 0.0; - if (requestedOperation == 'C') { - stored = 0.0; - } - return stored; - } -} |