- 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
Creating a List of Ring Tones
The extended RTTTLPlayer application, RTTTLEx, will show a list of five ring tones (tunes) on the cell phone screen. The user will then be allowed to select from this list.
Before I start programming, I need to solve a problem. How do I make it so that when a user selects a tune, say "TheFifth," the application knows to play the associated RTTTL file? I solve this problem by abstracting the tune into two parts: the caption of the ring tone, and the URL with which the caption is associated. I do this by creating two arrays (see Listing 1):
mcaptions will hold the captions
murls will hold the URLs
Listing 1 Creating the mcaptions and murls String Arrays
//Make the URL for the ring tones constant private static String website = "http://www.CogArtTech.com/tones/"; //Create an array of captions private String[] mcaptions = {"TheFifth","Octaves","Scales","Bach","LottaLove"}; /*Create an array of URLs where the elements will be associated with the captions array*/ private String[] murls = {website + "fifth.rtl", website + "octave.rtl", website + "minscale.rtl", website + "dmInvent.rtl", website + "love.rtl"};
Eventually I will pass both of these arrays to a class that renders the tune's captions on the cell phone's screen and plays the contents of the tune's URLin this case, an RTTTL stringon the cell phone. Because the offsets of both arrays, mcaptions and murls, are identical, each caption is implicitly associated to a corresponding URL. The first element in mcaptions ("TheFifth") is the caption of the tune; the first element in murls ("fifth.rtl") is the URL of that tune. The second element of mcaptions ("Octaves") is the caption of the second tune, matching the second element of murls ("octave.rtl"), and so forth.
NOTE
Notice that I isolate the base URL for the web site where the ring tones reside (my web site, www.CogArtTech.com) into the variable named website. I do this to make the code more compact and maintainable.
Once I have these two arrays made, it's time to assign the captions for the ring tones to an MIDP List component for display on the cell phone screen and make it so that the user can play a selected ring tone.