Mesin Pencari

Program ramalan gratis tentang Cinta, Karir dan Keberuntungan di blog ini sudah di tutup.

How to create a J2ME MIDP RSS Reader application with NetBeans 4.0

Contributed by Tommi Laukkanen as part of the Win With NetBeans comptetition

This tutorial will show you how to create a J2ME MIDP RSS Reader application with NetBeans 4.0. With RSS Reader you can read RSS feeds with your mobile device. This application is designed to work with MIDP 1.0 so it is also compatible with older devices.

In case you are new to RSS, it stands for Really Simple Syndication. RSS is a lightweight XML format designed for sharing headlines and other content like blogs and news. You can for example get the latest NetBeans.org news as a RSS feed from http://www.netbeans.org/rss-091.xml

Here are some screenshots of this application in action:
Launch Bookmarks Loading
Launch icon Bookmarks list Loading form
Headers Topic
Headers list Topic form


This tutorial will cover these subjects:
  • Creating new mobile application project with NetBeans 4.0
  • Configuring your NetBeans 4.0 project to allow the usage of 3rd party libraries (eg. kXML 2)
  • Using obfuscator to reduce distributable jar file's size with NetBeans 4.0
  • Running mobile application on emulator with NetBeans 4.0

Designing the application

The project has five source code files:

  • RssFeed.java, The code for the RSS feed class
  • RssItem.java, The code for the RSS feed item class
  • RssFeedParser.java, The code for the RSS feed parser class
  • Settings.java, The code for the settings utility class
  • RssReaderMIDlet.java, The code for the MIDlet class

This tutorial won't deeply explain the the functionality of each class. You can aquire source files http://www.netbeans.org/files/documents/4/308/RssReader_src.zip.

Requirements

You must have NetBeans IDE 4.0 and the NetBeans Mobility Pack 4.0 installed before you can start J2ME MIDP development. See the J2ME MIDP Development Download page for instructions on downloading and installing the complete environment. You also need to download http://www.kxml.org mobile class library. The latest version of the library on time of writing was 2.1.9. You can download the latest kXML release http://sourceforge.net/project/showfiles.php?group_id=9157. Download the kxml2-min.jar to any folder on your computer.

Creating a Mobile Class Library project

Create a new Mobile Application project

  1. Choose File > New project (Ctrl-Shift-N). Under Categories, select Mobile

  2. Select Mobile Application under Projects. Click Next.

  3. Under Project Name, type RSS Reader.

  4. Change the Project Location to any folder on your computer.

  5. Select Set as Main Project checkbox

  6. Unselect Create Hello MIDlet checkbox

  7. Click Finish.

  8. Now the project node in Projects window should look like this:

    Project node

Create new Java Packages for source files and application icon

  1. Right-click the RSS Reader project node in Projects window and select New > Java Package

  2. Under Package Name, type RssReader.

  3. Click Finish.

  4. Repeat the previous actions and add icons package

  5. Now you have requred packages for the source code files and the application icons.

Configure the project

  1. Right-click the RSS Reader project node in Projects window and select Properties.

  2. Select Application Descriptor > Attributes.

  3. Select MIDlet-Vendor line under General Attributes list and click Edit.

  4. Under Value, type your own name.

  5. Close the edit window by clicking OK button.

  6. Now we are going to add a reference to kXML library that you have downloaded on your computer.

  7. Select Build > Libraries & Resources.

  8. Click Add Jar/Zip.

  9. Browse to downloaded kxml2-min.jar file

  10. Now you have added the reference to kXML library and you can use the kXML parser in your application.

Creating the source code files

    Now we are going to create the source code for this project. Now you should have downloaded the existing source code files, as mentioned in the requirements section. You should now move them to your project folder's src/RssReader subfolder.

    After you have copied the source code files into the RssReader folder, the Project window's RssReader package should look the same as in the picture below. It could take a few second to refresh the packages content in the project window.

    Add files

    If you wouldn't have the source code ready, then you would use New > Java Class or New > Midlet features and then write your own code.

Add an icon to your application

    Now we are going to add an icon to our Mobile application.

  1. Right-click picture below and download it to RSS Reader project's src/icons/ subfolder

  2. App icon

  3. Right-click the RSS Reader project node in Projects window and select Properties.

  4. Select Application Descriptor > MIDlets.

  5. Click Add.

  6. The NetBeans IDE is smart enough to fill up all the fields as you only need to select the icon that you want your application to have.

  7. Under MIDlet Icon, select /icons/rss.png.

  8. Add MIDlet

  9. Close both windows by clicking the OK button.

Using Obfuscation to reduce MIDlet file size

Building the project

    Now we are going to build the project.

  1. Press F11 to build your project.

  2. Alternatively you could select Build > Build Main Project from the main menu.

  3. Right-click RSS_Reader.jar on the Files window and select Properties.

  4. Files

    Take a notice that jar file's size is almost 24kb.

    JAR size

  5. Right-click RSS Reader project node and select Properties.

  6. Select Build > Obfuscating

  7. Slide the Obfuscation Level to maximum value (=High).

  8. Click OK button.

  9. Rebuild the application pressing F11

  10. Right-click RSS_Reader.jar on the Files window and select Properties.

  11. Take a notice that jar file's size is reduced to 15kb bytes.

    JAR size

    As the memory usage in smaller mobile devices is a critical issue, therefore the obfuscating is very important part of the mobile application development. We have now saved almost 10 kb memory only by changing Obfuscator settings on our NetBeans IDE.

Using the emulator

Run the project

  1. Press F6 to Run the main project

  2. Alternatively you could select Run > Run Main Project

  3. Press Launch button on default emulator

    The RSS Reader is now running and you can use it to view RSS feeds. The following screenshots have been taken from Sony Ericsson emulator.

Launch Bookmarks Loading
Launch icon Bookmarks list Loading form
Headers Topic
Headers list Topic form

The end

Conclusion and development ideas

This concludes the J2ME MIDP RSS Reader tutorial. You may now easily continue on developing this application by adding new features. You could for example add a support for Atom XML feeds. Please keep me informed what ever you do with this code :)


Copied from http://www.netbeans.org/kb/articles/rss-reader.html

ANA PRIVAT

Jl. Maharta IV, Block A-19 No. 13, Pondok Maharta, Ciledug, Tangerang, Banten 15154. Telp. 021-926 48 700, 021-986 70 881

Baca Juga



1 comments:

andry yudha prawira said...

based on the j2me article, the research could be a reference link below

http://repository.gunadarma.ac.id/bitstream/123456789/1219/1/17110075.pdf
thank you

Post a Comment

Terima kasih telah meninggalkan komentar. Secepatnya akan saya balas komentar Anda. Salam hangat.

SMS Gateway is a program to manipulate SMS from your customer. It can be auto reply, scheduled broadcast and unscheduled broadcast. SMS gateway accelerating process incoming and outgoing information in your business and increase customer satisfaction. Your business need SMS Gateway program? Phone : 0815 100 932 90 Email : anaprivatku@gmail.com

Enter your email address:

Delivered by FeedBurner

 
---- Java Coffee. Green World Blogger Template---- © Template Design by Herro