Source Code Cross Referenced for Go.java in  » Web-Framework » Millstone » org » millstone » examples » gogame » 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.gogame 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.millstone.examples.gogame;
002:
003:        import org.millstone.base.Application;
004:        import org.millstone.base.data.Item;
005:        import org.millstone.base.data.Property;
006:        import org.millstone.base.data.util.IndexedContainer;
007:        import org.millstone.base.event.*;
008:        import org.millstone.base.ui.*;
009:
010:        /** The classic game 'Go' as an example for the Millstone framework. 
011:         *
012:         * @author IT Mill Ltd.
013:         * @see org.millstone.base.Application
014:         */
015:        public class Go extends Application implements  Action.Handler,
016:                Property.ValueChangeListener {
017:
018:            /* An IndexedContainer will hold the list of players - it can be
019:             * displayed directly by the 'Table' ui component. */
020:            private static IndexedContainer players = new IndexedContainer();
021:
022:            // This action will be triggered when a player challenges another.
023:            private static Action challengeAction = new Action("Challenge",
024:                    null);
025:
026:            // The players can have a current game.
027:            static {
028:                players.addContainerProperty("Current game", Game.class, null);
029:            }
030:
031:            // The layout
032:            private CustomLayout layout = new CustomLayout("goroom");
033:
034:            // Label to be displayed in the login window.
035:            private TextField loginName = new TextField(
036:                    "Who are you stranger?", "");
037:
038:            // Button for leaving the game
039:            private Button leaveButton = new Button("Leave game", this , "close");
040:
041:            // Button for logging in        
042:            private Button loginButton = new Button("Enter game", this , "login");
043:
044:            // A 'Table' ui component will be used to show the list of players.
045:            private Table playersTable;
046:
047:            // Our Go-board ('Board') component.
048:            private Board board = null;
049:
050:            /** The initialization method that is the only requirement for
051:             * inheriting the org.millstone.base.service.Application class. It will
052:             * be automatically called by the framework when a user accesses the
053:             * application.
054:             * We'll initialize our components here.
055:             */
056:            public void init() {
057:
058:                // Use the GO theme that includes support for goboard component
059:                // and goroom layout
060:                setTheme("gogame");
061:
062:                // Initialize main window with created layout
063:                addWindow(new Window("Game of GO", layout));
064:
065:                // Xreate a table for showing the players in the IndexedContainer 'players'.
066:                playersTable = new Table("Players", players);
067:                playersTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
068:                playersTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID);
069:                playersTable.addActionHandler(this );
070:                playersTable.setPageBufferingEnabled(false);
071:
072:                // Add the Table and a Button to the main window.       
073:                layout.addComponent(playersTable, "players");
074:                layout.addComponent(leaveButton, "logoutbutton");
075:
076:                // Hide game components
077:                leaveButton.setVisible(false);
078:                playersTable.setVisible(false);
079:
080:                // Add login functionality
081:                layout.addComponent(loginName, "loginname");
082:                loginButton.dependsOn(loginName);
083:                layout.addComponent(loginButton, "loginbutton");
084:            }
085:
086:            /** This function is called when a player tries to log in.
087:             */
088:            public void login() {
089:                String name = loginName.toString();
090:                if (name.length() > 0 && !players.containsId(name)) {
091:
092:                    // Login successful
093:                    setUser(name);
094:
095:                    // Add user to player list.
096:                    Item user = players.addItem(name);
097:                    ((Property.ValueChangeNotifier) user
098:                            .getItemProperty("Current game")).addListener(this );
099:
100:                    // Update visible components
101:                    layout.removeComponent(loginName);
102:                    layout.removeComponent(loginButton);
103:                    leaveButton.setVisible(true);
104:                    playersTable.setVisible(true);
105:                }
106:            }
107:
108:            // On logout, remove user from the player list
109:            public void close() {
110:                if (getUser() != null) {
111:
112:                    // Remove user from the player list.
113:                    players.removeItem(getUser());
114:                }
115:                super .close();
116:            }
117:
118:            /** Implementing the Action.Handler interface - this function returns
119:             * the available actions.
120:             * @see org.millstone.base.event.Action.Handler
121:             */
122:            public Action[] getActions(Object target, Object source) {
123:                Property p = players.getContainerProperty(target,
124:                        "Current game");
125:                if (p != null && target != null && !target.equals(getUser())) {
126:                    Game game = (Game) p.getValue();
127:                    if (game == null) {
128:                        return new Action[] { challengeAction };
129:                    }
130:                }
131:
132:                return new Action[] {};
133:            }
134:
135:            /** Implementing the Action.Handler interface - this function handles
136:             * the specified action.
137:             * @see org.millstone.base.event.Action.Handler
138:             */
139:            public void handleAction(Action action, Object sender, Object target) {
140:                if (action == challengeAction) {
141:                    Property p = players.getContainerProperty(target,
142:                            "Current game");
143:                    if (p != null && target != null
144:                            && !target.equals(getUser())) {
145:                        Game game = (Game) p.getValue();
146:                        if (game == null) {
147:                            game = new Game(9, (String) getUser(),
148:                                    (String) target);
149:                            p.setValue(game);
150:                            players.getContainerProperty(getUser(),
151:                                    "Current game").setValue(game);
152:                        }
153:                    }
154:                }
155:            }
156:
157:            /** Implementing the Property.ValueChangeListener interface - this function 
158:             * is called when a value change event occurs.
159:             * @see org.millstone.base.data.Property.ValueChangeListener
160:             */
161:            public void valueChange(Property.ValueChangeEvent event) {
162:                if (board != null)
163:                    layout.removeComponent(board);
164:                Game game = (Game) event.getProperty().getValue();
165:                if (game != null) {
166:                    board = new Board(game, game.getBlackPlayer() == getUser());
167:                    layout.addComponent(board, "board");
168:                }
169:            }
170:        }
171:
172:        /* This Millstone sample code is public domain. *  
173:         * 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.