Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

The Methods of a MIDlet

You may have noticed at the end of Listing 5 that the CommandListener for the MIDP list is the RTTTLEx class itself. Therefore, following the rules of Java interface implementation, RTTTLEx must implement a commandAction() method to handle keyboard input. (I'll show this in Listing 7, in the next section.) Through RTTTLEx's commandAction() method, tune playing will be facilitated. Before I can run the RTTTLEx application, however, in addition to the commandAction() method I must provide signatures for three methods that are required in a MIDlet app: startApp(), pauseApp(), and destroyApp(). I'll provide code for startApp() here, but leave pauseApp() and destroyApp() without code for now.

Remember that a cell phone may have many applications in residence—phone book, games, the workings to make an actual phone call—as well as your application. Thus, when the user selects your application from within a particular cell phone, the startApp() method is called (see Figure 6). You can think of startApp() as your application's constructor. The startApp() behavior that I provide is shown in Listing 6:

Listing 6 Starting the RTTTLEx application

public void startApp() {
  if (player != null ) {
      player.stopSound();
  }else{
      //Make a player
      player = new RTTTLExCanvas(display,
                   mcaptions,murls);
  }
  //make the list of tunes appear on
  //the mobile device screen
  display.setCurrent(theList);
}

Figure 6Figure 6 startApp() is invoked when the user selects a MIDlet in the cell phone..

The startApp() method for the RTTTLEx application creates a RTTTL tune player, called player, which is an instance of the RTTTLExCanvas class. startApp() also displays a list of available tunes on the screen by setting theList as the current display.

  • + Share This
  • 🔖 Save To Your Account