KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > microedition > midlet > MIDlet


1
2 /*
3  * MicroEmulator
4  * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20
21 package javax.microedition.midlet;
22
23 import javax.microedition.lcdui.Display;
24
25 import com.barteo.emulator.MIDletAccess;
26 import com.barteo.emulator.MIDletBridge;
27
28 public abstract class MIDlet
29 {
30     private boolean destroyed;
31
32     class MIDletAccessor extends MIDletAccess
33     {
34         public MIDletAccessor(MIDlet amidlet)
35         {
36             super(amidlet);
37         }
38
39         public void startApp() throws MIDletStateChangeException
40         {
41             MIDletBridge.setCurrentMIDlet(midlet);
42             getDisplayAccess().updateCommands();
43             midlet.startApp();
44         }
45
46         public void pauseApp()
47         {
48             midlet.pauseApp();
49         }
50
51         public void destroyApp(boolean unconditional) throws MIDletStateChangeException
52         {
53             if (!destroyed) {
54                 midlet.destroyApp(unconditional);
55             }
56             getDisplayAccess().clean();
57         }
58     }
59
60     
61     protected MIDlet()
62     {
63         MIDletBridge.setAccess(this, new MIDletAccessor(this));
64
65         // initialize display
66
Display.getDisplay(this);
67         destroyed = false;
68     }
69
70     
71     protected abstract void startApp() throws MIDletStateChangeException;
72
73     protected abstract void pauseApp();
74
75     protected abstract void destroyApp(boolean unconditional) throws MIDletStateChangeException;
76
77     
78     public final String getAppProperty(String key)
79     {
80         return MIDletBridge.getAppProperty(key);
81     }
82
83     
84     public final void notifyDestroyed()
85     {
86         destroyed = true;
87         MIDletBridge.notifyDestroyed();
88     }
89
90     
91     public final void notifyPaused()
92     {
93     }
94
95 }
96
Popular Tags