example.stock
Class StockMIDlet

java.lang.Object
  extended by javax.microedition.midlet.MIDlet
      extended by example.stock.StockMIDlet

public class StockMIDlet
extends javax.microedition.midlet.MIDlet

The MIDlet application class that we'll run for the Stock Demo.


Field Summary
(package private)  javax.microedition.lcdui.Display display
          The MIDlet's display object
 
Constructor Summary
StockMIDlet()
          Default constructor that is called by the application manager to create a new instance of this MIDlet after which the MIDlet enters the Paused state.
 
Method Summary
 void destroyApp(boolean unconditional)
          When the application management software has determined that the MIDlet is no longer needed, or perhaps needs to make room for a higher priority application in memory, is signals the MIDlet that it is a candidate to be destroyed by invoking the destroyApp(boolean) method.
 void pauseApp()
          This method is invoked by the application management software when the MIDlet no longer needs to be active.
 void startApp()
          This method is invoked when the MIDlet is ready to run and starts/resumes execution after being in the Paused state.
 
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

display

javax.microedition.lcdui.Display display
The MIDlet's display object

Constructor Detail

StockMIDlet

public StockMIDlet()
            throws javax.microedition.midlet.MIDletStateChangeException

Default constructor that is called by the application manager to create a new instance of this MIDlet after which the MIDlet enters the Paused state.

Throws:
javax.microedition.midlet.MIDletStateChangeException
Method Detail

startApp

public void startApp()

This method is invoked when the MIDlet is ready to run and starts/resumes execution after being in the Paused state. The MIDlet acquires any resources it needs, enters the Active state and begins to perform its service, which in this case means it displays the main menu on the screen.

The method proceeds like so:

  • open the StockDatabase and the AlertDatabase
  • read the settings data from the settings RecordStore
  • create the string to be scrolled across the Ticker on the top of the screens and instantiate the Ticker object using that string. That string will be constructed of the names and prices of the stocks in our database
  • get and store the MIDlet's Display object
  • create and show the main menu
  • instantiate the TimerTask and Timer and associate the two setting the refresh interval to the value of the refresh_interval variable
  • Specified by:
    startApp in class javax.microedition.midlet.MIDlet
    Throws:
    MIDletStateChangeException - is thrown if the MIDlet cannot start now but might be able to start at a later time.
    See Also:
    MIDlet

    pauseApp

    public void pauseApp()

    This method is invoked by the application management software when the MIDlet no longer needs to be active. It is a stop signal for the MIDlet upon which the MIDlet should release any resources which can be re-acquired through the startApp method which will be called upon re-activation of the MIDlet. The MIDlet enters the Paused state upon completion of this method.

    Specified by:
    pauseApp in class javax.microedition.midlet.MIDlet
    See Also:
    MIDlet

    destroyApp

    public void destroyApp(boolean unconditional)
                    throws javax.microedition.midlet.MIDletStateChangeException

    When the application management software has determined that the MIDlet is no longer needed, or perhaps needs to make room for a higher priority application in memory, is signals the MIDlet that it is a candidate to be destroyed by invoking the destroyApp(boolean) method. In this case, we need to destroy the RecordEnumerations so that we don't waste their memory and close the open RecordStores. If the RecordStores are empty, then we do not need them to be stored as they will be recreated on the next invokation of the MIDlet so we should delete them. At the end of our clean up, we must call notifyDestroyed which will inform the application management software that we are done cleaning up and have finished our execution and can now be safely terminated and enters the Destroyed state.

    Specified by:
    destroyApp in class javax.microedition.midlet.MIDlet
    Parameters:
    unconditional - If true when this method is called, the MIDlet must cleanup and release all resources. If false the MIDlet may throw MIDletStateChangeException to indicate it does not want to be destroyed at this time.
    Throws:
    MIDletStateChangeException - is thrown if the MIDlet wishes to continue to execute (Not enter the Destroyed state). This exception is ignored if unconditional is equal to true.
    javax.microedition.midlet.MIDletStateChangeException
    See Also:
    MIDlet