appmain
Class URLPage

java.lang.Object
  |
  +--menu.Page
        |
        +--appmain.URLPage
All Implemented Interfaces:
java.lang.Runnable

public class URLPage
extends Page
implements java.lang.Runnable

A URLPage is used to display the content of a single URL. This is a dynamic Page, since it may take a while for the URL to load and we must return quickly from the constructor and doCommandAction.


Field Summary
 
Fields inherited from class menu.Page
run, theThread
 
Constructor Summary
URLPage(java.lang.String label, java.lang.String url)
          Initialize a new URLPage object using the supplied parameters and default values where needed.
URLPage(java.lang.String label, java.lang.String title, javax.microedition.lcdui.Image icon, java.lang.String url)
          Initialize a new URLPage object using the supplied parameters.
 
Method Summary
 int doCommandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
          Process the user command and return an integer value telling the PageMgr what to do next.
 javax.microedition.lcdui.Displayable getDisplayable()
          Return the Displayable object for this URLPage, partially filled in and ready to display.
 void run()
          Do all the exciting connecting to the network and reading the contents from the URL.
 
Methods inherited from class menu.Page
getIcon, getLabel, getLinkedPage, getPrevious, getTitle, setPrevious, start
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLPage

public URLPage(java.lang.String label,
               java.lang.String title,
               javax.microedition.lcdui.Image icon,
               java.lang.String url)
Initialize a new URLPage object using the supplied parameters.

Parameters:
label - short label for this page (as might be used in a menu)
title - longer label for this page (as might be used in a screen title)
icon - small icon for this page (as might be used in a toolbar or menu)
url - the String describing the url to read

URLPage

public URLPage(java.lang.String label,
               java.lang.String url)
Initialize a new URLPage object using the supplied parameters and default values where needed. The title defaults to null (meaning that the label will be used in its place). The icon defaults to null (meaning text only will be displayed).

Parameters:
label - short label for this page (as might be used in a menu)
url - the String describing the url to read
Method Detail

doCommandAction

public int doCommandAction(javax.microedition.lcdui.Command c,
                           javax.microedition.lcdui.Displayable d)
Process the user command and return an integer value telling the PageMgr what to do next. This method handles the details of a command for a page, while the commandAction method in the PageMgr handles the general responsibility of switching displays.

Specified by:
doCommandAction in class Page
Parameters:
c - a Command object identifying the command.
d - the Displayable on which this event has occurred
Returns:
a pageAction code, selected from the public fields defined by PageMgr.

getDisplayable

public javax.microedition.lcdui.Displayable getDisplayable()
Return the Displayable object for this URLPage, partially filled in and ready to display.

Specified by:
getDisplayable in class Page
Returns:
the appropriate Displayable object for this Page

run

public void run()
Do all the exciting connecting to the network and reading the contents from the URL. This method is started when the PageMgr sets this page as the current displayable and then calls the start method. The method runs until completion or until the "run" variable is set to false by the user command thread. If run is set to false, then this method must immediately clean up any outstanding resource holdings that it has and return. It must not touch anything that is shared with other parts of the application because those objects (eg, the screen display) are assuming that this thread is history and the shared objects may already be gone or in use by another thread. Just clean up the local resource holdings and get out.

Any action that affects objects that other threads may access or change must be done within a synchronized block.

Any action that does not affect shared objects should not be done within a synchronized block so that the user command thread can dive in and out of this object concurrently with this thread.

Each little sychronized block is a unit that gets done atomically. Before starting the next one there's a chance that the user command thread will cancel this thread altogether by setting run to false.

Note that local variables in the run() method are allocated each time a new thread starts execution in run(). Instance variables are shared between all threads running in an object's run() method.

Specified by:
run in interface java.lang.Runnable