|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.midlet.MIDlet
ch.aplu.gidlet.Gidlet
public abstract class Gidlet
Abstract helper class derived from MIDlet to provide functionalities
for starting and stopping the application. Typically the application class
extends this class. To simplify the application programming, some useful
methods and static variables are declared, so that no explicit class or instance
identifier is needed.
The platform's call of startApp() will create a separate thread (called "main-thread")
that calls main(). The application class should override main() and perform
all operations in the main() method.
main() must terminate so that the main-thread stops running.
If an endless loop in main() is needed, test with isExiting()
whether the Exit soft button has been hit. If the program blocks in the loop because
of waitOk(), readXXX(), showMessage(), main() will terminate immediately when
the Exit soft button is hit.
In this case an endless loop with while (true) is permitted.
Keep in mind that before main() runs, the environment is not fully initialized.
Therefore do not create visible GUI elements as instance variables. If needed
you may declare them as instance variable and create them in main(). The standard
Gidlet GUI elements starting with the letter 'M' (MForm, MConsole, etc.) may be
created as instance variable because there is an internal mechanism that defers
their initilization until main() runs.
When the platform requests the Gidlet to terminate by calling destroyApp(),
the Gidlet will terminate by calling doExit() that calls notifyDestroyed(), if
neither destroyApp() nor doExit() is overridden.
Before calling main() a special thread will be started in order disable the
the screen saver from shading the screen. If the screen saver should remain active,
declare a constructor and call enableScreenSaver(true).
Nested Class Summary | |
---|---|
class |
Gidlet.HttpGetter
Class that creates a thread to transfer data using the HTTP GET command. |
class |
Gidlet.MMSReader
Class that creates a MMS server thread based on the Wireless Messaging API (WMA). |
class |
Gidlet.SMSReader
Class that creates a SMS server thread based on the Wireless Messaging API (WMA). |
Field Summary | |
---|---|
static int |
BLACK
The color black. |
static int |
BLUE
The color blue. |
static int |
CYAN
The color cyan. |
static int |
DARKGRAY
The color darkgray. |
static javax.microedition.lcdui.Display |
display
The current MIDlet's display. |
protected java.util.Vector |
displays
List of all displays created before main() is called. |
static int |
DOUBLE_VALIDATE
Validation type "Garantee to be a double" |
static int |
DOWN_PRESSED
Same as GameCanvas.DOWN_PRESSED. |
static int |
FIRE_PRESSED
Same as GameCanvas.FIRE_PRESSED. |
static int |
GAME_A_PRESSED
Same as GameCanvas.GAME_A_PRESSED. |
static int |
GAME_B_PRESSED
Same as GameCanvas.GAME_B_PRESSED. |
static int |
GAME_C_PRESSED
Same as GameCanvas.GAME_C_PRESSED. |
static int |
GAME_D_PRESSED
Same as GameCanvas.GAME_D_PRESSED. |
static int |
GRAY
The color gray. |
static int |
GREEN
The color green. |
static int |
INT_VALIDATE
Validation type "Garantee to be an integer" |
static int |
LEFT_PRESSED
Same as GameCanvas.LEFT_PRESSED. |
static int |
LIGHTGRAY
The color lightgray. |
static int |
LONG_VALIDATE
Validation type "Garantee to be a long" |
static int |
MAGENTA
The color magenta. |
static Gidlet |
myGidlet
A reference to the current gidlet. |
static int |
NONE_VALIDATE
Validation type "No validation" |
static int |
ORANGE
The color orange. |
static int |
PINK
The color pink. |
static int |
RED
The color red. |
static int |
RIGHT_PRESSED
Same as GameCanvas.RIGHT_PRESSED. |
protected java.util.Vector |
turtles
List of all turtles created before main() is called. |
static int |
UP_PRESSED
Same as GameCanvas.UP_PRESSED. |
static int |
WHITE
The color white. |
static int |
YELLOW
The color yellow. |
Constructor Summary | |
---|---|
Gidlet()
Constructs a Gidlet instance and perform a few initializations. |
Method Summary | |
---|---|
static void |
beep(int type)
Plays a system sound of given type. |
protected void |
closeTimedMessage()
Closes a timed message box before timeout expires. |
static void |
delay(int time)
Delays execution for the given amount of time (in ms). |
protected void |
destroyApp(boolean b)
Called when the platform requests to terminate the program. |
protected void |
doExit()
Terminates the application by calling wakeUp() and notifyDestroyed(). |
protected void |
doOk()
Empty. |
protected void |
doPause()
Empty. |
static boolean |
getDebug()
Returns true if debug information is turned on. |
static Gidlet |
getGidlet()
Returns a reference to the current gidlet instance. |
static javax.microedition.lcdui.Image |
getImage(java.lang.String imageUrl)
Loads image from given resource and returns it's Image reference. |
javax.microedition.lcdui.Image |
getImageHttp(java.lang.String imageUri,
int timeout)
Loads image from given HTTP uri and returns it's Image reference. |
static byte[] |
getResource(java.lang.String resourceUrl)
Loads resource into byte array. |
static javax.microedition.lcdui.game.Sprite |
getSprite(java.lang.String imageUrl)
Loads image from given resource and returns it's Sprite reference. |
static javax.microedition.lcdui.game.Sprite |
getSprite(java.lang.String imageUrl,
int frameWidth,
int frameHeight)
Loads image from given resource with given frameWidth, frameHeight and returns it's Sprite reference. |
static java.lang.Thread |
getThread()
Returns the main thread. |
static long |
getTime()
Gets timer's time (in ms). |
static java.lang.String |
getVersion()
Returns version information of Gidlet framework. |
protected void |
internalNotifyHttpResponse(byte[] data,
int code)
|
static boolean |
isEmulator()
Returns true, if the application runs in the emulator, otherwise false. |
static boolean |
isExiting()
Returns true, if the Exit soft button is hit in a readXXX(), showMessage() or showTimeMessage() method. |
static boolean |
isSleeping()
Returns true, if putSleep() was called and still waiting for wakeUp() or timeout. |
void |
keyPressed(int keyCode)
Empty implementation of KeyListener.keyPressed(). |
void |
keyReleased(int keyCode)
Empty implementation of KeyListener.keyReleased(). |
void |
keyRepeated(int keyCode)
Empty implementation of KeyListener.keyRepeated(). |
abstract void |
main()
Abstract declaration, must be overridden by derived class. |
protected void |
messageTimeout()
Will be called when the timeout of the timed message expires. |
void |
notifyHttpResponse(byte[] response,
int httpCode)
Empty callback method triggered by HttpReader when the transfer due to the HTTP GET command issued by the HttpGetter constructor terminates or when an error occured. |
void |
notifyHttpResponse(java.lang.String response,
int httpCode)
Empty callback method triggered by HttpReader when the transfer due to the HTTP GET command issued by the HttpGetter constructor terminates or when an error occured. |
void |
notifyIncomingMMS(javax.wireless.messaging.MultipartMessage mpm)
Empty callback method triggered by the MMSReader thread when a MMS is received. |
void |
notifyIncomingSMS(javax.wireless.messaging.TextMessage msg)
Empty callback method triggered by the SMSReader thread when a SMS is received. |
void |
notifyOutgoingMMS(int status)
Empty callback method triggered by the sendMMS() and sendMMSMail() thread when it terminates. |
void |
notifyPlayerUpdate(java.lang.String event,
java.lang.Object eventData)
Empty callback method triggered by the PlayerListener when the state of the Player is updated. |
protected void |
pauseApp()
Called when the platform requests to pause the program. |
static boolean |
putSleep()
Same as putSleep(int timeout) with timeout = 0 (timeout disalbed). |
static boolean |
putSleep(int timeout)
Puts the current thread in a wait state until wakeUp() is called or timeout (in ms) expires. |
protected static double |
readDouble(java.lang.String prompt)
Shows a simple form with an input field with the given prompt message and no initial value. |
protected static double |
readDouble(java.lang.String prompt,
double init)
Shows a simple form with an input field with the given prompt message, and given initial value. |
java.lang.String |
readFile(java.lang.String fileUrl)
Reads content of a text file from a given url. |
protected static int |
readInt(java.lang.String prompt)
Shows a simple form with an input field with the given prompt message and no initial value. |
protected static int |
readInt(java.lang.String prompt,
int init)
Shows a simple form with an input field with the given prompt message and given initial value. |
protected static long |
readLong(java.lang.String prompt)
Shows a simple form with an input field with the given prompt message and no initial value. |
protected static long |
readLong(java.lang.String prompt,
long init)
Shows a simple form with an input field with the given prompt message and given initial value. |
protected static java.lang.String |
readString(java.lang.String prompt)
Shows a simple form with an input field with the given prompt message and no initial value. |
protected static java.lang.String |
readString(java.lang.String prompt,
java.lang.String init)
Shows a simple form with an input field with the given prompt message, and given initial value. |
static java.lang.String |
readTextResource(java.lang.String fileUrl)
Reads and returns text from a textfile with given URL. |
void |
run()
Gidlet's run-method implementation. |
protected static void |
sendMMS(java.lang.String phonenumber,
java.lang.String appId,
java.lang.String subject,
javax.wireless.messaging.MessagePart[] parts)
Sends a MMS to given phone number with given application identifier, subject, and message parts. |
protected static void |
sendMMS(java.lang.String phonenumber,
java.lang.String appId,
java.lang.String subject,
javax.wireless.messaging.MessagePart[] parts,
java.lang.String startContentId)
Sends a MMS to given phone number with given application identifier, subject, message parts and startContentId. |
protected static void |
sendMMSMail(java.lang.String recipient,
java.lang.String subject,
java.lang.String message)
Sends an e-mail via MMS with given recipient's e-mail address, subject and message. |
protected static int |
sendSMS(java.lang.String phonenumber,
int portnumber,
java.lang.String text)
Sends a SMS with given text to given phone and SMS port number. |
protected static int |
sendSMS(java.lang.String phonenumber,
java.lang.String text)
Sends a SMS with given text to given phone number (and no SMS port number). |
static void |
setDebug(boolean debug)
Turns on/off debug information on System.out (default: off). |
protected void |
showDebug(java.lang.String msg)
Displays given debug message on System.out, when debugging is enabled by setDebug(true). |
static void |
showMessage(java.lang.String msg)
Shows a simple form with an output field that contains the given message. |
static void |
showMessage(java.lang.String msg,
boolean restore)
Shows a simple form with an output field that contains the given message. |
protected void |
showTimedMessage(java.lang.String msg,
int duration)
Shows a simple form during the given duration (in ms) with an output field that contains the given message. |
static java.lang.String[] |
split(java.lang.String s,
java.lang.String separator)
Splits given string with given separator string into multiple strings. |
protected void |
startApp()
Implementation of MIDlet.startApp(). |
static void |
startTimer()
Starts a timer or restart it by setting its time to zero. |
protected static void |
waitOk()
Waits until the OK soft button is hit. |
protected static void |
waitOk(boolean addOkButton)
Waits until a OK soft button is hit. |
static void |
wakeUp()
Wakes up the waiting thread. |
Methods inherited from class javax.microedition.midlet.MIDlet |
---|
checkPermission, getAppProperty, notifyDestroyed, notifyPaused, platformRequest, resumeRequest |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector displays
protected java.util.Vector turtles
public static javax.microedition.lcdui.Display display
public static Gidlet myGidlet
public static final int BLACK
public static final int BLUE
public static final int CYAN
public static final int DARKGRAY
public static final int GRAY
public static final int GREEN
public static final int LIGHTGRAY
public static final int MAGENTA
public static final int ORANGE
public static final int PINK
public static final int RED
public static final int WHITE
public static final int YELLOW
public static final int NONE_VALIDATE
public static final int INT_VALIDATE
public static final int LONG_VALIDATE
public static final int DOUBLE_VALIDATE
public static final int FIRE_PRESSED
public static final int GAME_A_PRESSED
public static final int GAME_B_PRESSED
public static final int GAME_C_PRESSED
public static final int GAME_D_PRESSED
public static final int LEFT_PRESSED
public static final int RIGHT_PRESSED
public static final int UP_PRESSED
public static final int DOWN_PRESSED
Constructor Detail |
---|
public Gidlet()
Method Detail |
---|
protected void startApp()
startApp
in class javax.microedition.midlet.MIDlet
public static java.lang.Thread getThread()
public abstract void main()
protected void pauseApp()
pauseApp
in class javax.microedition.midlet.MIDlet
protected void destroyApp(boolean b)
destroyApp
in class javax.microedition.midlet.MIDlet
public void keyPressed(int keyCode)
keyPressed
in interface KeyListener
public void keyReleased(int keyCode)
keyReleased
in interface KeyListener
public void keyRepeated(int keyCode)
keyRepeated
in interface KeyListener
public void run()
run
in interface java.lang.Runnable
protected void doExit()
protected void doPause()
protected void doOk()
protected static void waitOk(boolean addOkButton)
protected static void waitOk()
protected static int readInt(java.lang.String prompt, int init)
protected static int readInt(java.lang.String prompt)
protected static long readLong(java.lang.String prompt, long init)
protected static long readLong(java.lang.String prompt)
protected static double readDouble(java.lang.String prompt, double init)
protected static double readDouble(java.lang.String prompt)
protected static java.lang.String readString(java.lang.String prompt, java.lang.String init)
protected static java.lang.String readString(java.lang.String prompt)
public static void showMessage(java.lang.String msg, boolean restore)
public static void showMessage(java.lang.String msg)
protected void showTimedMessage(java.lang.String msg, int duration)
protected void messageTimeout()
protected void closeTimedMessage()
public static java.lang.String readTextResource(java.lang.String fileUrl)
public static javax.microedition.lcdui.Image getImage(java.lang.String imageUrl)
public static byte[] getResource(java.lang.String resourceUrl)
public javax.microedition.lcdui.Image getImageHttp(java.lang.String imageUri, int timeout)
protected void internalNotifyHttpResponse(byte[] data, int code)
public static javax.microedition.lcdui.game.Sprite getSprite(java.lang.String imageUrl)
public static javax.microedition.lcdui.game.Sprite getSprite(java.lang.String imageUrl, int frameWidth, int frameHeight)
protected static int sendSMS(java.lang.String phonenumber, int portnumber, java.lang.String text)
protected static int sendSMS(java.lang.String phonenumber, java.lang.String text)
public void notifyIncomingSMS(javax.wireless.messaging.TextMessage msg)
Gidlet.SMSReader
protected static void sendMMS(java.lang.String phonenumber, java.lang.String appId, java.lang.String subject, javax.wireless.messaging.MessagePart[] parts, java.lang.String startContentId)
notifyOutgoingMMS(int)
protected static void sendMMS(java.lang.String phonenumber, java.lang.String appId, java.lang.String subject, javax.wireless.messaging.MessagePart[] parts)
notifyOutgoingMMS(int)
protected static void sendMMSMail(java.lang.String recipient, java.lang.String subject, java.lang.String message)
notifyOutgoingMMS(int)
public void notifyOutgoingMMS(int status)
sendMMS(java.lang.String, java.lang.String, java.lang.String, javax.wireless.messaging.MessagePart[], java.lang.String)
,
sendMMSMail(java.lang.String, java.lang.String, java.lang.String)
public void notifyIncomingMMS(javax.wireless.messaging.MultipartMessage mpm)
Gidlet.MMSReader
public void notifyHttpResponse(byte[] response, int httpCode)
new String(data)
Keep in mind that callback method must return quickly. Avoid calls to
blocking methods.
Gidlet.HttpGetter
public void notifyHttpResponse(java.lang.String response, int httpCode)
Gidlet.HttpGetter
public static void beep(int type)
public static java.lang.String getVersion()
public static Gidlet getGidlet()
public static void startTimer()
public static long getTime()
public static void delay(int time)
public static boolean putSleep(int timeout)
public static boolean putSleep()
public static void wakeUp()
public static boolean isSleeping()
putSleep(int)
,
wakeUp()
public void notifyPlayerUpdate(java.lang.String event, java.lang.Object eventData)
PlayerListener
public static boolean isEmulator()
public static boolean isExiting()
public static void setDebug(boolean debug)
showDebug(java.lang.String)
public static boolean getDebug()
public static java.lang.String[] split(java.lang.String s, java.lang.String separator)
public java.lang.String readFile(java.lang.String fileUrl)
protected void showDebug(java.lang.String msg)
setDebug(boolean)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |