Source Code Cross Referenced for Guess.java in  » Web-Framework » rife-1.6.1 » tutorial » numberguess » 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 » rife 1.6.1 » tutorial.numberguess 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03:         * Distributed under the terms of either:
04:         * - the common development and distribution license (CDDL), v1.0; or
05:         * - the GNU Lesser General Public License, v2.1 or later
06:         * $Id: Guess.java 3634 2007-01-08 21:42:24Z gbevin $
07:         */
08:        package tutorial.numberguess;
09:
10:        import com.uwyn.rife.engine.Element;
11:        import com.uwyn.rife.template.Template;
12:        import tutorial.numberguess.backend.Contest;
13:        import tutorial.numberguess.backend.Game;
14:
15:        /**
16:         * This element handles guesses that are being made by participants in a game.
17:         * <p>
18:         * If an active game is detected, it is resumed. Otherwise, a new game is
19:         * started.
20:         * <p>
21:         * The visitor is able to submit a guess through a form. The element validates
22:         * the answer and keeps track of the number of guesses. The user receives an
23:         * indication about the relation of the correct answer with the last submitted
24:         * guess. If the guess was correct, the <code>success</code> exit is activated.
25:         *
26:         * @author Geert Bevin (gbevin[remove] at uwyn dot com)
27:         * @version $Revision: 3634 $
28:         */
29:        public class Guess extends Element {
30:            private Game game;
31:
32:            private String gameid;
33:            private int guess = -1;
34:
35:            public void setGameid(String gameid) {
36:                this .gameid = gameid;
37:            }
38:
39:            public void setGuess(int guess) {
40:                this .guess = guess;
41:            }
42:
43:            /**
44:             * An instance of the template that's being used by the element instance.
45:             */
46:            private Template template;
47:
48:            /**
49:             * The element's initialization.
50:             */
51:            public void initialize() {
52:                // obtain the active game
53:                game = Contest.getGame(gameid);
54:                // if no game could be found, start a new one
55:                if (null == game) {
56:                    exit("start");
57:                }
58:
59:                // retrieve the html template
60:                template = getHtmlTemplate("guess");
61:            }
62:
63:            /**
64:             * The element's entry point.
65:             */
66:            public void processElement() {
67:                // output the template
68:                print(template);
69:            }
70:
71:            /**
72:             * Processes a guess when the form has been submitted.
73:             */
74:            public void doPerformGuess() {
75:                // validate the guess
76:                if (guess < 0 || guess > 100) {
77:                    // if the guess was invalid, a warning is shown and the logic is
78:                    // interrupted
79:                    template.setBlock("warning", "invalid");
80:                } else {
81:                    // increase the number of guess attempts
82:                    game.increaseGuesses();
83:
84:                    // check the correctness of the guess in case of a successful match, the
85:                    // success exit is triggered, otherwise an indication message is shown
86:                    if (game.getAnswer() < guess) {
87:                        template.setBlock("indication", "lower");
88:                    } else if (game.getAnswer() > guess) {
89:                        template.setBlock("indication", "higher");
90:                    } else {
91:                        setOutput("gameid", gameid);
92:                        exit("success");
93:                    }
94:                }
95:
96:                // output the template
97:                print(template);
98:            }
99:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.