Comments
L W wrote: Dear Sir, Please do forward a Google Wave Invitation to lvw.iv4 (at) gmail (dot) com, at your earliest convenience? Much appreciated!
Cloud Expo on Google News

SYS-CON.TV

2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
Building a Simple VocabBuilder Application
Creating a good impression

To make a good impression, one needs to have a good vocabulary. Management Professionals, University Professors, or GRE/GMAT aspirants - we all benefit from a decent set of words in this competitive world. There are different ways we can improve our vocabulary, such as reading novels, articles, dictionaries and so on, but we often find very little time to do so.

During our "down-time" - when we are stuck in traffic for hours, or standing in some long queue - our mobile phone is often our only source of entertainment. If our mobiles - which one in three people already carry - had word-tutors, this time could be efficiently used to learn new adjectives, verbs and nouns.

To build such an application, words need to be stored in a database. Since simple database implementation (RMS) is dynamic, the database needs to be built on every new mobile, after application is installed. To remove this overhead, the only way to maintain the word-list is in a file. Because of some programming related issues, j2me does not provide a full fledged API for file access. Still, there are ways to use a file in a j2me application. In a Vocab Builder application, words and their meanings, stored in those files randomly, can be retrieved.

There are "n" number of constraints with mobile programming - such as power, speed, UI size, memory size limitations, and many others - which make programming for mobile applications difficult. Probably, this is the reason why we see very few attempts to create such software. However, a simple vocabulary builder can be implemented without much effort. The following article can be used as a guideline to develop a simple vocabulary builder for your mobile phone.

First, let's look at Implementation Diagram, as shown in Figure 1.

All classes from the above diagram are explained in this article. Let's start with the MIDlet class. Our application will have a MIDlet that will initiate the application.

VocabBuilder Class
Let's define this MIDlet Class and name it VocabBuilder (see Figure 2).

public class VocabBuilder extends MIDlet implements CommandListener {

This VocabBuilder MIDlet displays the operations menu for the user. The menu provides different functions that are supported by the VocabBuilder tool. Since the tool has 5 functionalities, the same are provided in the operations menu.

menuList = new List("Expert Vocab Building",List.IMPLICIT);
menuList.append("Learn Adjectives",adjectivesImage);
menuList.append("Learn Verbs", adjectivesImage);
menuList.append("Learn Nouns", adjectivesImage);
menuList.append("Add words", verbsImage);
menuList.append("View / Delete words", verbsImage);
menuList.append("Help ",helpImage);

To provide the word-list, a file is used as a datastore. In this class, a string that contains the name of this file stores different words and their meanings. Providing the get() method for this variable will ensure that the get() method returns the name of the file currently in use by the application.

private String wordDatabaseFile;

As shown in Figure 3, the menu UI is displayed after the displayList() function of the VocabBuilder class is called on.

After the user selects a particular option from List, the corresponding operation is performed by implementing the CommandListener Interface. In need of a common algorithm to implement functionality of the first three options, we call on the method of getRandomWords() of the accessFile class. This class will, in turn, fetch the words and display them on the Form. But before calling on the aforementioned method, we need to set the value for the wordDatabaseFile string.

else if (c == List.SELECT_COMMAND)
    {
      int selection=menuList.getSelectedIndex();
      switch(selection)
      {
      case 0:
        wordDatabaseFile = "adjectives.kw";
        accessFile.getRandomWords();
        break;
      case 1:
        wordDatabaseFile = "verbs.kw";
        accessFile.getRandomWords();
        break;
      case 2:
        wordDatabaseFile = "nouns.kw";
        accessFile.getRandomWords();
        break;
      case 3:
        AddWordsToDictionary awdForm = new AddWordsToDictionary(this);
        Display.getDisplay(this).setCurrent(awdForm);
        awdForm = null
        break;
      case 4:
        DeleteWord dw = new DeleteWord(this);
        dw = null;
        break;
      case 5:
        HelpForm helpForm = new HelpForm(this);
        Display.getDisplay(this).setCurrent(helpForm);
        helpForm = null;
        break;
      }
    }

For the last three options, different classes are intitialized. These classes, in turn, will provide the functionality for adding, updating, deleting, and viewing the custom Dictionary.

AccessFile Class
This class fetches three random words at a time from the selected file as shown in Figure 4. In order to display these words, this class needs to extend Form Class.

public class AccessFile extends Form implements CommandListener

Note: Generally, when people read words that are consecutive, they tend to get bored. Hence, the random words generation strategy can be used to retain the interest of the user.

We need a "Next" button in order to display the next set of random words. This application opens the file in which word-meaning pairs are stored. We all have come across the apothegm, "different people, different needs". Accordingly, the user can choose a "learning area" appropriate to his or her needs. Some people are weak in adjectives, whereas others are weak in nouns, so different interfaces are provided for nouns, adjectives and verbs. Since implementation of all three is identical, an AccessFile class was created. To open the file and read the contents, the following function is used:

inputStream = getClass().getResourceAsStream(vb.getDataFileName());

inputStream is an object of InputStream class. Using getClass.getResourceAsStream(), we can open the file that is stored in the "res" library of the application package. After opening the file, we need to position the cursor in a random position. This can be done using following function:

inputStream.skip(selectRandom.getRandomPosition())

Here, a selectRandom class is used, which returns the random position in the file. By using the skip function of inputStream object, we reposition the cursor in a random position.

After a random position has been selected, the selected words can be fetched. Take extra care in the format in which the selected file is stored. Since the file used in the application has a word-meaning pair in a line the following strategy is used for fetching:

for(int j = 0; j<3;j++)
    {
    /** Create the word by adding all the characters */
    while ((tempCharRead = inputStream.read()) != -1 &&
       tempCharRead != '\n' )
    {
       word_meaning[j] = word_meaning[j]+ (char) tempCharRead;
    }
    this.append(wordMeaning);
    }

Since a word and its meaning are separated by a colon, the pair can be displayed in the same way on Form, using the append() method. In formatting, string item data type can be used. Next and Exit buttons are provided on the form for navigating through the word list.

    if (cmd == nextCommand)
       getRandomWords();
    else if (cmd == exitCommand) vb.displayList();
       // This is the main MIDlet Operations List.

If the user presses the next button, the application displays a new set of words, whereas if Exit is selected, the application takes control to the main List.

SelectRandom Class
This class fetches the file and depending on its size, it generates a random value. If the value generated is positioned towards last word, then the application might display only one or two words instead of three. In order to avoid this the maximum value to be generated can be set:

int skipValue= Math.abs((int) System.currentTimeMillis() % count);

The maximum feasible number that will prevent the display of less than three randomly generated words is "count". A more sophisticated algorithm can be used for generating the random number.

AddWordsToDictionary Class


About Kanchan Waikar
Kanchan Waikar is a software professional working with an IT company. She is very much inclined toward mobile programming. Her hobbies include reading novels, painting, playing table tennis, and programming.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

There's a lot of scope for improving, and seondly, think of more applications, ideas do matter!

To make a good impression, one needs to have a good vocabulary. Management Professionals, University Professors, or GRE/GMAT aspirants - we all benefit from a decent set of words in this competitive world. There are different ways we can improve our vocabulary, such as reading novels, articles, dictionaries and so on, but we often find very little time to do so.


Your Feedback
Mr. X wrote: There's a lot of scope for improving, and seondly, think of more applications, ideas do matter!
JDJ News Desk wrote: To make a good impression, one needs to have a good vocabulary. Management Professionals, University Professors, or GRE/GMAT aspirants - we all benefit from a decent set of words in this competitive world. There are different ways we can improve our vocabulary, such as reading novels, articles, dictionaries and so on, but we often find very little time to do so.
Latest AJAXWorld RIA Stories
Performance implications of certain CSS Selectors are not specific to a certain JavaScript Library like Prototype. I recently blogged about the internals of CSS Selectors in jQuery. The same holds true for every JavaScript library that offers CSS Selectors. Certain lookups can be...
Adobe put out this press release - well, kinda, it was released at 6am Saturday morning and the company didn't bother to tell its staff about it, least of all its sales people. Anyway, it's about how Acrobat.com, Adobe's contribution to the flock of Office-challenging web apps, h...
The .append() method is perhaps the most misused of all jQuery methods. While an extremely useful and easy method to work with, it dramatically affects the performance of your page. When misused, the .append() method can cripple your JavaScript code's performance. When used well,...
Recently I installed the Beta 2 version of "Geneva", or ADFS 2.0. All of my machines are now Windows 7 machines, including just about all of my VHDs and virtual machines. The only time I use Win2k8 R2 is when the product I'm installing specifically requires me to do that. So when...
SYS-CON Events (http://events.sys-con.com) announced today that the "show prospectus" for the 5th International Cloud Computing Conference & Expo (www.CloudComputingExpo.com) is now shipping. 5th International Cloud Expo will take place April 19-21, 2010, at the Jacob Javits C...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE