␡
- 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
Selecting a Tune
RTTTL tunes are listed on the RTTTLEx screen and played using the class RTTTLExCanvas. When the user selects a tune from the List object in RTTTLEx using the cell phone's up- and down-arrow buttons, and then presses the Play button, the Command object playCommand is trapped in RTTTLEx's commandAction() method, as shown in Listing 7:
Listing 7 Processing Commands in the RTTTLEx Class
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); }else if ((s == theList && c == List.SELECT_COMMAND) || c == playCommand) { //Find out which tune has been selected int i = theList.getSelectedIndex(); //Let the tune player, RTTTLExCanvas, know which //tune has been selected player.setIndex(i); //Attach the player as the current //UI display display.setCurrent(player); //do all necessary screen redrawing player.serviceRepaints(); //play the tune! player.playSound(); } }
The actual work of getting the RTTTL file from the Internet and playing it is encapsulated in the class RTTTLExCanvas.