The following example and files are provided without warranty of any kind. Use at your own risk.
Mobile Recipe Database
Have you ever been at the grocery store buying the ingredients for your favorite recipes but you forgot to bring the recipe?
If you had the recipes on your cell phone, this wouldn't be a problem!
The following is a simple J2ME example application that maintains recipes database. Of course, it would be difficult to
actually type in these recipes on your cell phone, so we'll use a Java servlet web service that has the lster" list of recipes.
This list could be maintained by a Web Application (not provided here). Our J2ME application will be have the following features:
- Maintain a local list of recipes on the cell phone. This list can be synchronized with the master database. Individual recipes can be deleted.
- View the details of the recipe including the ingredients.
- Configure the URL of the Web Service providing the master list of recipes.
Recipe DB MIDlet
The RecipeDB application will have the following classes.
- Recipe: We need a class to store a single recipe in memory. Let's define a recipe as having three fields.
- Name: the name of the recipe.
- Ingredients: string containing he ingredients (and the instructions?).
- RecordID: a unique ID associated with the record stored on the cell phone
- RecipeManager: A singleton class that manages the recipes on the phone including synchronization.
- SyncListener : An listener interface for synchronization events.
- RecipeDBMIDlet extends MIDlet: This is our MIDlet, the entry point to our J2ME application.
- MainMenu extends javax.microedition.lcdui.List: A J2ME List screen displaying the main menu.
- URLForm extends javax.microedition.lcdui.Form: A form for editing the URL to the Recipe server.
- RecipeList extends javax.microedition.lcdui.List: GUI for the recipe list.
- RecipeDetailScreen extends javax.microedition.lcdui.TextBox: Displays the recipe ingredients in a text box.
- MainMenu extends Form: A singleton class that manages the recipes on the phone including synchronization.
- SyncProgressForm extends Form: A form displaying a progress guage while the app is talking to the server.
Downloads
- MIDlet source code
- RecipeDB.jad JAD file. Note, this jad points to the jar on this server. If you have Sun's wireless toolkit installed, you can open this from your browser to run the MIDlet. Be sure to update this jad when deploying elsewhere.
- RecipeDB.jar J2ME binary
Recipe DB Server
This is a very simple web service with a single servlet that reads from a single MySQL table.
- Servlet source code
- Servlet WAR file
- MySQL files .sql files