/* License
*
* Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
* AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
* AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of any
* nuclear facility.
*/
/* imports */
import javax.microedition.midlet.*;
public class MyMidlet extends MIDlet {
/**
* PropertyOutput - lookup and report one application property.
*/
private void PropertyOutput( String key ) {
String value = getAppProperty( key );
if ( value != null )
System.out.println( key + " = " + value );
}
/**
* PropertyReport - detect and report MIDlet run-time environment.
*/
private void PropertyReport() {
final int Npush = 10; /* maximum number of Push's to report */
final int Nmidlet = 10; /* maximum number of MIDlet's to report */
final String key[] = { /* standard names */
"MIDlet-Name",
"MIDlet-Version",
"MIDlet-Vendor",
"MIDlet-Icon",
"MIDlet-Description",
"MIDlet-Info-URL",
"MIDlet-Jar-URL",
"MIDlet-Jar-Size",
"MIDlet-Data-Size",
"MicroEdition-Profile",
"MicroEdition-Configuration",
"MIDlet-Permissions",
"MIDlet-Permissions-Opt",
"MIDlet-Install-Notify",
"MIDlet-Delete-Notify",
"MIDlet-Delete-Confirm",
null
};
final String push_key = "MIDlet-Push-";
final String midlet_key = "MIDlet-";
int i;
for ( i=0; key[i] != null; ++i ) /* report standard properties */
PropertyOutput( key[i] );
for ( i=1; i <= Npush; ++i ) /* report push entries */
PropertyOutput( push_key + i );
for ( i=1; i <= Nmidlet; ++i ) /* report MIDlet entries */
PropertyOutput( midlet_key + i );
return;
}
/**
* MyMIDlet - constructor
*/
public MyMidlet() {
// pre-condition: state is undefined
System.out.println( "MyMIDlet()" );
// allocate per instance resources
PropertyReport();
System.out.println( "MyMIDlet: return" );
// post-condition: state is Paused
}
/**
* startApp - MIDlet has entered the Active state.
*/
public void startApp() {
// pre-condition: state is Paused.
System.out.println( "startApp()" );
// allocate resources required while in the Active state.
System.out.println( "startApp: return" );
// post-condition: state is Active
}
/**
* pauseApp - enter the Paused state.
*/
public void pauseApp() {
// pre-condition: state is Active
System.out.println( "pauseApp()" );
// release any resoruces not required while Paused
System.out.println( "pauseApp(): return" );
// post-condition: state is Paused
}
/**
* destroyApp - enter the Destroyed state.
*
* @param unconditional
*/
public void destroyApp( boolean unconditional ) throws MIDletStateChangeException {
// pre-condition: state is Active or Paused
System.out.println( "destroyApp( " + unconditional + " )" );
if ( unconditional == false ) { // can opt not to be destroyed
// decide if termination is acceptable, re-assign unconditional
}
/*
* These two steps should be considered unconditional since throwing the
* exception may not be honored. See the note associated with the destroyApp
* API in JSR-118, p445-446
*/
// save data to persistent storage
// release per instance resources allocated in the constructor.
if ( unconditional == false ) {
System.out.println( "destroyApp: throw exception" );
throw new MIDletStateChangeException();
}
System.out.println( "destroyApp: return" );
// post-condition: state is Destroyed
}
}