Source Code Cross Referenced for Calc.java in  » Web-Framework » Millstone » org » millstone » examples » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » Millstone » org.millstone.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.millstone.examples;
002:
003:        import org.millstone.base.ui.*;
004:
005:        /** <p>An example application implementing a simple web-based calculator.
006:         * using the MillStone UI library. The application opens up a window and
007:         * places the needed UI components (display label, buttons etc.) on it, and
008:         * registers a button click listener for them.</p>
009:         * 
010:         * <p>When any of the buttons are pressed the application finds out which
011:         * button was pressed, figures what that button does, and updates the user
012:         * interface accordingly.</p>
013:         *
014:         * @see org.millstone.base.Application
015:         * @see org.millstone.base.ui.Button.ClickListener
016:         */
017:        public class Calc extends org.millstone.base.Application implements 
018:                Button.ClickListener {
019:
020:            /** The label used as the display */
021:            private Label display = null;
022:
023:            /** Last completed result */
024:            private double stored = 0.0;
025:
026:            /** The number being currently edited. */
027:            private double current = 0.0;
028:
029:            /** Last activated operation. */
030:            private String operation = "C";
031:
032:            /** Button captions. */
033:            private static String[] captions = // Captions for the buttons
034:            { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0",
035:                    "=", "C", "+" };
036:
037:            /** <p>Initializes the application. This is the only method a MillStone
038:             * application is required to implement. It's called by the framework
039:             * and it should perform whatever initialization tasks the application
040:             * needs to perform.</p>
041:             * 
042:             * <p>In this case we create the main window, the display, the grid to
043:             * hold the buttons, and the buttons themselves.</p>
044:             */
045:            public void init() {
046:
047:                /*
048:                 * Create a new {@link org.millstone.base.ui.GridLayout GridLayout}
049:                 * to hold the UI components needed by the calculator.
050:                 */
051:                GridLayout layout = new GridLayout(4, 5);
052:
053:                //Create a new label component for displaying the result
054:                display = new Label(Double.toString(current));
055:                display.setCaption("Result");
056:
057:                // Place the label to the top of the previously created grid.
058:                layout.addComponent(display, 0, 0, 3, 0);
059:
060:                // Create the buttons and place them in the grid
061:                for (int i = 0; i < captions.length; i++) {
062:                    layout.addComponent(new Button(captions[i], this ));
063:                }
064:
065:                /*
066:                 * Create the main window with a caption and add it to the
067:                 * application.
068:                 */
069:                addWindow(new Window("MillStone calculator", layout));
070:
071:            }
072:
073:            /** <p>The button listener method called any time a button is pressed.
074:             * This method catches all button presses, figures out what the user
075:             * wanted the application to do, and updates the UI accordingly.</p>
076:             * 
077:             * <p>The button click event passed to this method contains information
078:             * about which button was pressed. If it was a number, the currently
079:             * edited number is updated. If it was something else, the requested
080:             * operation is performed. In either case the display label is updated
081:             * to include the outcome of the button click.</p>
082:             * 
083:             * @param event the button click event specifying which button was
084:             * pressed
085:             */
086:            public void buttonClick(Button.ClickEvent event) {
087:
088:                try {
089:                    // Number button pressed
090:                    current = current
091:                            * 10
092:                            + Double
093:                                    .parseDouble(event.getButton().getCaption());
094:                    display.setValue(Double.toString(current));
095:                } catch (java.lang.NumberFormatException e) {
096:
097:                    // Operation button pressed
098:                    if (operation.equals("+"))
099:                        stored += current;
100:                    if (operation.equals("-"))
101:                        stored -= current;
102:                    if (operation.equals("*"))
103:                        stored *= current;
104:                    if (operation.equals("/"))
105:                        stored /= current;
106:                    if (operation.equals("C"))
107:                        stored = current;
108:                    if (event.getButton().getCaption().equals("C"))
109:                        stored = 0.0;
110:                    operation = event.getButton().getCaption();
111:                    current = 0.0;
112:                    display.setValue(Double.toString(stored));
113:                }
114:            }
115:        }
116:
117:        /* This Millstone sample code is public domain. *  
118:         * For more information see www.millstone.org.  */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.