Source Code Cross Referenced for BBall.java in  » IDE-Netbeans » mobility » example » audiodemo » 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 » IDE Netbeans » mobility » example.audiodemo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Copyright (c) 2007, Sun Microsystems, Inc.
004:         *
005:         * All rights reserved.
006:         *
007:         * Redistribution and use in source and binary forms, with or without
008:         * modification, are permitted provided that the following conditions
009:         * are met:
010:         *
011:         *  * Redistributions of source code must retain the above copyright
012:         *    notice, this list of conditions and the following disclaimer.
013:         *  * Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in the
015:         *    documentation and/or other materials provided with the distribution.
016:         *  * Neither the name of Sun Microsystems nor the names of its contributors
017:         *    may be used to endorse or promote products derived from this software
018:         *    without specific prior written permission.
019:         *
020:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031:         */
032:        package example.audiodemo;
033:
034:        import javax.microedition.lcdui.*;
035:        import javax.microedition.midlet.*;
036:
037:        /*
038:         * this is a sample program to show ring tones synchronized with
039:         * selected background music.
040:         * It is based on the manyballs midlet. When a ball hits a wall,
041:         * a ring tone is heard.
042:         *
043:         * Usage: Use right arrow key to add one more ball (5 is the maximum).
044:         *        Use left arrow key to delete one ball
045:         *        Use up   arrow key to increase the speed of ball
046:         *        Use down arrow key to reduce the speed of ball
047:         *
048:         * @version
049:         */
050:        public class BBall extends MIDlet implements  CommandListener, Runnable {
051:            private static final String[] bgs = { "no background",
052:                    "wave background", "tone seq background", "MIDI background" };
053:            static String wavbgUrl;
054:            static String midbgUrl;
055:            private static final Object gameLock = new Object();
056:            private Command exitCommand = new Command("Exit", Command.EXIT, 1);
057:            private Command playCommand = new Command("Play", Command.ITEM, 1);
058:            private Display display;
059:            private int idx = 0;
060:            private List theList;
061:            private BallCanvas game;
062:
063:            // if this MIDlet's startApp method is started
064:            // for the first time
065:            private boolean firstTime = true;
066:
067:            // pause/resume support
068:            private boolean restartOnResume = false;
069:
070:            public BBall() {
071:                display = Display.getDisplay(this );
072:                theList = new List("Bouncing Ball", Choice.IMPLICIT);
073:
074:                for (int i = 0; i < bgs.length; i++) {
075:                    theList.append(bgs[i], null);
076:                }
077:
078:                wavbgUrl = getAppProperty("BBall-wav-URL");
079:                midbgUrl = getAppProperty("BBall-MIDI-URL");
080:                theList.addCommand(playCommand);
081:                theList.addCommand(exitCommand);
082:                theList.setCommandListener(this );
083:            }
084:
085:            // also called from BallCanvas
086:            public void displayList() {
087:                display.setCurrent(theList);
088:            }
089:
090:            /**
091:             * Called when this MIDlet is started for the first time,
092:             * or when the MIDlet returns from paused mode.
093:             *
094:             * If it is the first time, display the menu list.
095:             *
096:             * Otherwise, wake up the thread. If music was playing
097:             * when the MIDlet was paused, call the game's
098:             * start method.
099:             */
100:            public void startApp() {
101:                if (firstTime) {
102:                    displayList();
103:                    firstTime = false;
104:                } else {
105:                    SmallBall.paused = false;
106:
107:                    if ((game != null) && restartOnResume) {
108:                        game.start();
109:                    }
110:
111:                    restartOnResume = false;
112:                }
113:            }
114:
115:            /**
116:             * Called when this MIDlet is paused.
117:             * Pause the thread.
118:             * If the game is not already paused, call its pause method.
119:             * For consistency across different VM's,
120:             * it's a good idea to stop the player if
121:             * it's currently playing.
122:             */
123:            public void pauseApp() {
124:                SmallBall.paused = true;
125:                restartOnResume = ((game != null) && !game.isPaused());
126:
127:                if (restartOnResume) {
128:                    game.pause();
129:                }
130:            }
131:
132:            /**
133:             * Destroy must cleanup everything not handled
134:             * by the garbage collector.
135:             */
136:            public void destroyApp(boolean unconditional) {
137:                synchronized (gameLock) {
138:                    if (game != null) {
139:                        game.destroy();
140:                    }
141:                }
142:            }
143:
144:            /*
145:             * Respond to commands, including exit
146:             * On the exit command, cleanup and notify that the MIDlet has
147:             * been destroyed.
148:             */
149:            public void commandAction(Command c, Displayable s) {
150:                if (c == exitCommand) {
151:                    synchronized (gameLock) {
152:                        if (game != null) {
153:                            game.destroy();
154:                            game = null;
155:                        }
156:                    }
157:
158:                    destroyApp(false);
159:                    notifyDestroyed();
160:                } else if (((s == theList) && (c == List.SELECT_COMMAND))
161:                        || (c == playCommand)) {
162:                    idx = theList.getSelectedIndex();
163:                    new Thread(this ).start();
164:                }
165:            }
166:
167:            public void run() {
168:                synchronized (gameLock) {
169:                    if (game == null) {
170:                        game = new BallCanvas(this );
171:                    }
172:
173:                    display.setCurrent(game);
174:                    game.init(8, idx);
175:
176:                    if (game.needAlert()) {
177:                        Alert alert = new Alert("Warning",
178:                                "Cannot create player", null, null);
179:                        alert.setTimeout(1000);
180:                        display.setCurrent(alert, game);
181:                    }
182:
183:                    game.start();
184:                }
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.