The main class of the btsppEcho MIDlet is MIDletApplication, which handles the MIDlet state model callbacks. The actual user interface is delegated to appropriate screen-specific classes.
For information about the key aspects of implementing the MIDlet main class and UI classes, see:
The MIDletApplication class provides a central "state model" for the various MIDlet screens, so that each screen calls back to the MIDletApplication class and the MIDletApplication class then displays the appropriate next screen.
The MIDletApplication class also generates a UUID value for the application, uniquely identifying it. In this MIDlet, the UUID identifies the ConnectionService of the client, because the server initiates connections to the clients.
private final static String UUID = "A55665EE9F9146109085C2055C888B39";
The SettingsList class implements the first screen displayed by the MIDlet. It is used to define the MIDlet settings and start the MIDlet.
The following settings are defined:
Client or server mode
Inquiry type used by the client to be discoverable or by the server to perform a discovery
Whether authentication is used
If authentication is used:
Whether encryption is used
Whether authorization is used
On the screen, the user can select Start to start the MIDlet in the appropriate mode and using the appropriate settings. The MIDlet performs the start through an appropriate callback to the MIDletApplication class, which manages the screen transitions. The user can also select BT properties to view certain system properties related to Bluetooth usage, such as the number of other devices the Bluetooth device allows to be connected.
The ClientForm class implements the main screen of the MIDlet when it is run in the client mode.
The screen displays the number of open connections, status strings as connections are created and deleted or as messages are sent, and simple text messages as they are received from a remote server.
The ServerForm class implements the main UI screen of a connected MIDlet when it is run in the server mode. The screen is used to receive messages from a remote client and echo those back to all connected clients. This allows the MIDlet to be used as a very simple chat-like server.
The screen shows the number of connected clients. If one client disconnects, it has no effect on the connectivity between the server and any other clients.
When the MIDlet is run in the server mode, it must first search for suitable clients to create connections to. The ServiceDiscoveryList class implements a screen that is used to perform device inquiry and service discovery, and to open connections to selected clients. After the connections are opened, the ServerForm screen is displayed through a callback to the MIDletApplication class.
The ServiceDiscoveryList class uses the setTitle method to dynamically modify the screen’s title string during device inquiry and service discovery to indicate to the user that a more time-consuming activity is taking place. This approach for providing an "activity indicator" is used to keep the MIDlet code relatively simple. In your own MIDlets, you can use a separate transient canvas screen to graphically indicate that a potentially time-consuming activity is being processed.
The amount of time required for the device inquiry and service discovery depends on how many Bluetooth devices are within range, and on the number of devices which may be, or actually are, running the service. Test your Bluetooth MIDlets both in locations with just a few nearby Bluetooth devices and in locations with dozens of Bluetooth devices.
TheTextScreen class implements a simple read-only text screen. It contains a back command, which is used to move to the next appropriate UI screen state through the appropriate MIDletApplication callback.
The LogScreen class implements a screen which can be useful to give the user a way to follow the progress of the device inquiry and service discovery phases.
The target end users for this example MIDlet are developers learning to use the Java Bluetooth API. A log screen is provided to allow them to follow the progress of the Bluetooth phases. The screen is also a helpful debugging aid for more sophisticated end users.