Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build Brilliant Client/Server Apps with J2ME, PHP, and MySQL : Page 2

In this article you'll see how to make the three technologies work together by developing a simple and useful application that lets you update a multi-user blog and download the latest posts from it.


advertisement
Building a Wireless Blog
Nowadays, many developers have their own blog. For this reason the sample project for this article is a mobile application that lets you update a multi-user blog from wherever you are. By "multi-user blog" I mean a blog that can be managed and updated by different users provided that they own an account within the blog. Because of this multi-use aspect, the application allows users to read posts created by other users with blog accounts. Figure 3, Figure 4, Figure 5, and Figure 6 should clarify the intent and overall functionality of the application.

 
Figure 3. Main menu: The figure shows the start-up screen of the Client application.
 
Figure 4. Login Form: Here's the form where users enter their credentials.
 
Figure 5. Writing a Post: Here users enter the title and text for a post.
 
Figure 6. Downloading a Post: When you transmit the post author's username the application retrieves that author's latest post.
I'll dissect these figures one by one to help you gain an understanding of the client application's functional requirements.

Figure 3 shows the main menu of the application. Basically, you can choose to:

  • Write a new post and upload it to your server.
  • Download a post from your server.
  • Logout from the application.
When you first launch the program, you'll see the Login form shown in Figure 4. The information users enter into this form is permanently stored on their mobile device using RMS (Record Management System) so users won't see this form or need to login on subsequent launches. The application uses the login credentials to upload and download posts to and from the Web server. The startApp method checks whether the login data is already stored:

protected void startApp() { // check if the login info is already stored if (isLoginEmpty()) { setDisplay(fmLogin); } else { setDisplay(lsMain); } } ... private boolean isLoginEmpty() { RecordManager rm = new RecordManager("LOGIN"); return (rm.numRecords() < 2); }

The isLoginEmpty method checks the number of records present within the LOGIN record store. Delving into RMS and how to store data in your MIDP applications is beyond the scope of this article. All you need to know in this context is that you can store information in your mobile device using records. Each record contains a byte array. For the LOGIN record store I used the first record to store the username and the second for the password. Hence, if the number of records is less than two the login data hasn't yet been stored, so the application displays the Login form is displayed. The RecordManager class is simply a wrapper for the RMS-related classes. Of course, you can always reset the login information by selecting the Logout option.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap