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 icon | Bookmarks list | Loading form |
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
Choose File > New project (Ctrl-Shift-N). Under Categories, select Mobile
Select Mobile Application under Projects. Click Next.
Under Project Name, type RSS Reader.
Change the Project Location to any folder on your computer.
Select Set as Main Project checkbox
Unselect Create Hello MIDlet checkbox
Click Finish.
Now the project node in Projects window should look like this:
Create new Java Packages for source files and application icon
Right-click the RSS Reader project node in Projects window and select New > Java Package
Under Package Name, type RssReader.
Click Finish.
Repeat the previous actions and add icons package
Now you have requred packages for the source code files and the application icons.
Configure the project
Right-click the RSS Reader project node in Projects window and select Properties.
Select Application Descriptor > Attributes.
Select MIDlet-Vendor line under General Attributes list and click Edit.
Under Value, type your own name.
Close the edit window by clicking OK button.
Select Build > Libraries & Resources.
Click Add Jar/Zip.
Browse to downloaded kxml2-min.jar file
Now we are going to add a reference to kXML library that you have downloaded on your computer.
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.
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
Right-click picture below and download it to RSS Reader project's src/icons/ subfolder
Right-click the RSS Reader project node in Projects window and select Properties.
Select Application Descriptor > MIDlets.
Click Add.
Under MIDlet Icon, select /icons/rss.png.
Close both windows by clicking the OK button.
Now we are going to add an icon to our Mobile application.
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.
Using Obfuscation to reduce MIDlet file size
Building the project
Press F11 to build your project.
Right-click RSS_Reader.jar on the Files window and select Properties.
Right-click RSS Reader project node and select Properties.
Select Build > Obfuscating
Slide the Obfuscation Level to maximum value (=High).
Click OK button.
Rebuild the application pressing F11
Right-click RSS_Reader.jar on the Files window and select Properties.
Now we are going to build the project.
Alternatively you could select Build > Build Main Project from the main menu.
Take a notice that jar file's size is almost 24kb.
Take a notice that jar file's size is reduced to 15kb bytes.
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
Press F6 to Run the main project
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.
Alternatively you could select Run > Run Main Project
Launch icon | Bookmarks list | Loading form |
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
1 comments:
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.