␡
- Understanding the Java WTK
- The RTTTLEx Application
- Creating a List of Ring Tones
- Understanding the MIDP List Class
- Working with the Display Object and the Displayable Interface
- Configuring Commands
- Registering CommandListeners
- The Methods of a MIDlet
- Selecting a Tune
- The MIDP Canvas Object
- Playing a Tune
- Conclusion
Like this article? We recommend
Registering CommandListeners
As mentioned earlier, an instance of the MIDP List class (theList) implements the Displayable interface. The Displayable interface requires that a CommandListener be registered to it in order to process user input. I set the CommandListener in the constructor of RTTTLEx, as shown in Listing 5.
Listing 5 The Constructor for RTTTLEx
public RTTTLEx() { instance = this; display = Display.getDisplay(this); //Create a new MIDP List theList = new List("RTTTLEx Ring Tones", Choice.IMPLICIT); //Traverse the captions array and add the array's contents //to the list. for (int i = 0; i < mcaptions.length; i++) { theList.append(mcaptions[i], null); } //Add Command objects to the List object theList.addCommand(playCommand); theList.addCommand(exitCommand); //Register the List to be the //CommandListener for the application theList.setCommandListener(this); }