<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jimmy&#039;s Blog &#187; jimmy</title>
	<atom:link href="http://jimmod.com/blog/author/jimmy/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimmod.com/blog</link>
	<description>My name is Jimmy, and this is my story... ;)</description>
	<lastBuildDate>Fri, 14 Oct 2011 17:26:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android Market error on downloading (Error Downloading. There is insufficient space on the device.)</title>
		<link>http://jimmod.com/blog/2011/10/android-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device/</link>
		<comments>http://jimmod.com/blog/2011/10/android-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 17:26:09 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[My Life]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[insufficient]]></category>
		<category><![CDATA[market]]></category>
		<category><![CDATA[on]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[the]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=255</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		Today suddenly when I want to download an application from my Android tablet, I receiving this error : &#8220;Error Downloading xyzxyz. There is insufficient space on the device.&#8221;
It&#8217;s only displaying the error on downloading application with big size.
After browsing around, I found out that the cache folder (that I assume used [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F10%2Fandroid-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/10/android-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Android Market error on downloading (Error Downloading. There is insufficient space on the device.)" data-url="http://jimmod.com/blog/2011/10/android-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>Today suddenly when I want to download an application from my Android tablet, I receiving this error : &#8220;Error Downloading xyzxyz. There is insufficient space on the device.&#8221;<br />
It&#8217;s only displaying the error on downloading application with big size.</p>
<p>After browsing around, I found out that the cache folder (that I assume used by the market) is using small partition (around 20mb in my case).<br />
<span id="more-255"></span><br />
So to solve this we need to change it to bigger partition.</p>
<ol>
<li>You gonna need Android Terminal Simulator or equivalent terminal app. This will also require your Android rooted.</li>
<li> Type &#8217;su&#8217; (root permission request will be showned, you need to approve it).</li>
<li>Type &#8216;cd /&#8217;</li>
<li>Type &#8216;umount /cache&#8217;</li>
<li>Type &#8216;mount -o rw,remount -t rootfs rootfs /&#8217; (to set the folder access to rw &#8211; read write)</li>
<li>Type &#8216;rmdir /cache&#8217; (delete cache folder)</li>
<li>I personally using root explorer to do point 5-6</li>
<li>Type &#8216;mkdir /sdcard/cache&#8217;</li>
<li>Type &#8216;ln -s /sdcard/cache /cache&#8217; (to link cache folder to /sdcard/cache &#8211; which shoud have bigger partition size)</li>
</ol>
<p>Done.<br />
Try to rerun your Android Market and download big applications</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/10/android-market-error-on-downloading-error-downloading-there-is-insufficient-space-on-the-device/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Java ME (J2ME) JSON Implementation For Array Object</title>
		<link>http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/</link>
		<comments>http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 16:47:04 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[javame]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=246</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		One of the comment in JSON ME tutorial (http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/) asking about how to parse this kind of JSON :

&#123;\”api_status\”: \”OK\”,\”threads\”: &#91;&#123;\&#34;tid\&#34;: \&#34;2\&#34;,\&#34;title\&#34;: \&#34;First Title\&#34; }, { \&#34;tid\&#34;: \&#34;4\&#34;, \&#34;title\&#34;: \&#34;this is 2nd Title\&#34;}]}
&#60;span id=&#34;more-246&#34;&#62;&#60;/span&#62;

Latest JSON ME library : https://github.com/upictec/org.json.me/
From the JSON format we can easily see that the object have 2 [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/' rel='bookmark' title='Permanent Link: Using mock object with jmock 2'>Using mock object with jmock 2</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F09%2Fjava-me-j2me-json-implementation-for-array-object%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Java ME (J2ME) JSON Implementation For Array Object" data-url="http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>One of the comment in JSON ME tutorial (<a href="../2010/03/java-me-j2me-json-implementation-tutorialsample/">http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/</a>) asking about how to parse this kind of JSON :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>\”api_status\”<span style="color: #339933;">:</span> \”OK\”,\”threads\”<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>\<span style="color: #0000ff;">&quot;tid<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>First Title<span style="color: #000099; font-weight: bold;">\&quot;</span> }, { <span style="color: #000099; font-weight: bold;">\&quot;</span>tid<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>4<span style="color: #000099; font-weight: bold;">\&quot;</span>, <span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>this is 2nd Title<span style="color: #000099; font-weight: bold;">\&quot;</span>}]}
&lt;span id=&quot;</span>more<span style="color: #339933;">-</span><span style="color: #cc66cc;">246</span><span style="color: #0000ff;">&quot;&gt;&lt;/span&gt;</span></pre></div></div>

<p>Latest JSON ME library : <a href="https://github.com/upictec/org.json.me/">https://github.com/upictec/org.json.me/</a></p>
<p>From the JSON format we can easily see that the object have 2 property:</p>
<ul>
<li>api_status : String</li>
<li>threads : Array of object</li>
</ul>
<p>The Threads Object:</p>
<ul>
<li>tid : Integer</li>
<li>title : String</li>
</ul>
<p>My solution is not exactly the same because I have different approach on handling the arrays.</p>
<p>First I will make the threads class, I name it ThreadData. It should also implement the JSONable interface (<a href="http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/" target="_blank">see the 1st tutorial for the code</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ThreadData <span style="color: #000000; font-weight: bold;">implements</span> JSONAble <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> tid<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> title<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getTid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> tid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTid<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> tid<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tid</span> <span style="color: #339933;">=</span> tid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTitle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> title<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTitle<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> title<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">title</span> <span style="color: #339933;">=</span> title<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> fromJSON<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> jsonString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			JSONObject json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setTid<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setTitle<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toJSON<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		JSONObject inner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tid&quot;</span>, getTid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span>, getTitle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> inner.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> getTid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span> <span style="color: #339933;">+</span> getTitle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Above implementation is just like the <a href="http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/" target="_blank">1st tutorial</a>, the main class JSONable implementation is different. Please focus on the JSONArray usage.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Response <span style="color: #000000; font-weight: bold;">implements</span> JSONAble <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> api_status<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getApi_status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> api_status<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setApi_status<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> apiStatus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		api_status <span style="color: #339933;">=</span> apiStatus<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getThreads<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> threads<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setThreads<span style="color: #009900;">&#40;</span>ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">threads</span> <span style="color: #339933;">=</span> threads<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> fromJSON<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> jsonString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			JSONObject json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setApi_status<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;api_status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			JSONArray jsonArray <span style="color: #339933;">=</span> json.<span style="color: #006633;">getJSONArray</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;threads&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #339933;">=</span> jsonArray.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadData<span style="color: #009900;">&#91;</span>total<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>total<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">String</span> threadsJSON <span style="color: #339933;">=</span> jsonArray.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">fromJSON</span><span style="color: #009900;">&#40;</span>threadsJSON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			setThreads<span style="color: #009900;">&#40;</span>threads<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toJSON<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		JSONObject inner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;api_status&quot;</span>, getApi_status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			JSONArray jsonArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads <span style="color: #339933;">=</span> getThreads<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>threads.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				jsonArray.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toJSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;threads&quot;</span>, jsonArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> inner.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> response <span style="color: #339933;">=</span> getApi_status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">;</span>
		ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads <span style="color: #339933;">=</span> getThreads<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>threads.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			response <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;[&quot;</span> <span style="color: #339933;">+</span> threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> response<span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So when you setup the startapp function:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Converting Object to JSON</span>
		Response response <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Response<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ThreadData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">setTid</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;First Title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">setTid</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		threads<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;this is 2nd Title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		response.<span style="color: #006633;">setApi_status</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		response.<span style="color: #006633;">setThreads</span><span style="color: #009900;">&#40;</span>threads<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Convert to JSON : &quot;</span><span style="color: #339933;">+</span>response.<span style="color: #006633;">toJSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//Converting JSON to Object</span>
		<span style="color: #003399;">String</span> sample <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>api_status<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>SAMPLE<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>threads<span style="color: #000099; font-weight: bold;">\&quot;</span>:[<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>tid<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:10,<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>3rdTitle<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>}<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>tid<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:15,<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>this is 4th Title<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>}<span style="color: #000099; font-weight: bold;">\&quot;</span>]}&quot;</span><span style="color: #339933;">;</span>
		Response reponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Response<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		response.<span style="color: #006633;">fromJSON</span><span style="color: #009900;">&#40;</span>sample<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Convert from JSON : &quot;</span><span style="color: #339933;">+</span> response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It will have output:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">Convert to JSON : {&quot;api_status&quot;:&quot;OK&quot;,&quot;threads&quot;:[&quot;{\&quot;tid\&quot;:2,\&quot;title\&quot;:\&quot;First Title\&quot;}&quot;,&quot;{\&quot;tid\&quot;:4,\&quot;title\&quot;:\&quot;this is 2nd Title\&quot;}&quot;]}
Convert from JSON : SAMPLE-[10-3rdTitle][15-this is 4th Title]</pre></div></div>

<p>It demonstrate the sample for creating JSON string and parsing JSON string which have array/object inside the JSON.</p>
<p></code></p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/' rel='bookmark' title='Permanent Link: Using mock object with jmock 2'>Using mock object with jmock 2</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</title>
		<link>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/</link>
		<comments>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 12:42:27 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[8583]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[iso 8583]]></category>
		<category><![CDATA[jimmy]]></category>
		<category><![CDATA[jpos]]></category>
		<category><![CDATA[pack]]></category>
		<category><![CDATA[packager]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[unpack]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=225</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		ISO 8583 Tutorial article

Introduction for Beginners
Build and Parse ISO Message using JPOS library
????

In the beginning
OK after my article about ISO 8583 let&#8217;s go deeper into programming using Java + JPOS library.
Quote from JPOS website:
jPOS is a Java® platform-based, mission-critical, ISO-8583 based financial transaction library/framework that can be customized and extended in [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners</a></li><li><a href='http://jimmod.com/blog/2007/11/simple-log4j-implementation/' rel='bookmark' title='Permanent Link: Simple Log4J implementation'>Simple Log4J implementation</a></li><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F07%2Fjimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library" data-url="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><h2 style="font-size: 1.5em;"><strong>ISO 8583 Tutorial article</strong></h2>
<ul>
<li><a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/">Introduction for Beginners</a></li>
<li><a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/">Build and Parse ISO Message using JPOS library</a></li>
<li>????</li>
</ul>
<h2><strong>In the beginning</strong></h2>
<p>OK after <a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/">my article about ISO 8583</a> let&#8217;s go deeper into programming using Java + JPOS library.</p>
<p>Quote from <a href="http://www.jpos.org/" target="_blank">JPOS website</a>:</p>
<blockquote><p>jPOS is a Java® platform-based, mission-critical, ISO-8583 based financial transaction library/framework that can be customized and extended in order to implement financial interchanges.</p></blockquote>
<p>So first thing to do is download JPOS from it website.</p>
<p>Then we setup our development environment by creating Java Project using your favorites IDE. Add to the project all jar in JPOS library.<br />
Here&#8217;s my Eclipse  package explorer looks like.<br />
<span id="more-225"></span></p>
<div id="attachment_226" class="wp-caption aligncenter" style="width: 306px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/package-explorer.png"><img class="size-medium wp-image-226" title="package explorer" src="http://jimmod.com/blog/wp-content/uploads/2011/07/package-explorer-296x300.png" alt="package explorer" width="296" height="300" /></a><p class="wp-caption-text">package explorer</p></div>
<h2><strong>Create Data Elements (DE) types XML</strong></h2>
<p>Like I said that ISO 8583 is a &#8217;standard&#8217; which mean can be different between one implementation and another <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
To put it simple, although there&#8217;s a (some) standard for DE list sometime we need to change it.<br />
Either way, we need to tell JPOS how our DE will be formatted or packaged.</p>
<p>Since in the complete XML there&#8217;s 128 DE, I&#8217;ll quote only the DE # we used. Full xml can be <a href="http://jimmod.com/blog/wp-content/uploads/2011/07/basic.xml">downloaded here (basic.xml)</a></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;no&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE isopackager SYSTEM &quot;genericpackager.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isopackager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;4&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MESSAGE TYPE INDICATOR&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_NUMERIC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;64&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BIT MAP&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_BITMAP&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;6&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;PROCESSING CODE&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_NUMERIC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;4&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;12&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;AMOUNT, TRANSACTION&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_NUMERIC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;7&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;TRANSMISSION DATE AND TIME&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_NUMERIC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;11&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;6&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SYSTEM TRACE AUDIT NUMBER&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_NUMERIC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;44&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;25&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ADITIONAL RESPONSE DATA&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_LLCHAR&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isofield</span></span>
<span style="color: #009900;">      <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;105&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;999&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;RESERVED ISO USE&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpos.iso.IFA_LLLCHAR&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isopackager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The XML should easily understand in each isofield tag we define:</p>
<ul>
<li>id : the DE number</li>
<li>length : the max/fixed length of the DE</li>
<li>name : yes, it&#8217;s the name or description</li>
<li>class : this define the type of the DE, which in this case represent by the JPOS class. You can see the whole <a href="http://www.jpos.org/doc/javadoc/org/jpos/iso/package-summary.html" target="_blank">class list here</a>. I only list some of it.
<ul>
<li>IFA_NUMERIC : Numeric &#8211; Left padder with zeros.</li>
<li>IFA_BITMAP : For ISO Bitmap</li>
<li>IFA_LLCHAR : ASCII variable len CHAR &#8211; 2 digit length info</li>
<li>IFA_LLLCHAR : ASCII variable len CHAR &#8211; 3 digit length info</li>
</ul>
</li>
</ul>
<p>So this XML will be used for build (pack) ISO Message or parse (unpack) ISO Message.</p>
<p>You will need the <a href="http://jimmod.com/blog/wp-content/uploads/2011/07/genericpackager.dtd">XML data schema (genericpackager.dtd)</a> to be put on same directory with basic.xml</p>
<h2 style="font-size: 1.5em;">Build (pack) ISO Message</h2>
<p>Below is the code. The code is quite straight forward, review it first and I&#8217;ll discuss a bit afterward.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gnu.jimmod.iso8583.utility</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.ISOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.ISOMsg</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.packager.GenericPackager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BuildISOMessage <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ISOException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create Packager based on XML that contain DE type</span>
		GenericPackager packager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenericPackager<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;basic.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Create ISO Message</span>
		ISOMsg isoMsg <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ISOMsg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">setPackager</span><span style="color: #009900;">&#40;</span>packager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">setMTI</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0200&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #0000ff;">&quot;201234&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">&quot;10000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span>, <span style="color: #0000ff;">&quot;110722180&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">11</span>, <span style="color: #0000ff;">&quot;123456&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">44</span>, <span style="color: #0000ff;">&quot;A5DFGR&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">105</span>, <span style="color: #0000ff;">&quot;ABCDEFGHIJ 1234567890&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// print the DE list</span>
		logISOMsg<span style="color: #009900;">&#40;</span>isoMsg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Get and print the output result</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #339933;">=</span> isoMsg.<span style="color: #006633;">pack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RESULT : &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> logISOMsg<span style="color: #009900;">&#40;</span>ISOMsg msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;----ISO MESSAGE-----&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;  MTI : &quot;</span> <span style="color: #339933;">+</span> msg.<span style="color: #006633;">getMTI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span>msg.<span style="color: #006633;">getMaxField</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #006633;">hasField</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;    Field-&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; : &quot;</span><span style="color: #339933;">+</span>msg.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ISOException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--------------------&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The output:</p>
<pre>----ISO MESSAGE-----
  MTI : 0200
    Field-3 : 201234
    Field-4 : 10000
    Field-7 : 110722180
    Field-11 : 123456
    Field-44 : A5DFGR
    Field-105 : ABCDEFGHIJ 1234567890
--------------------
RESULT : 0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890</pre>
<p>The program flow:</p>
<ol>
<li>Create ISO packager based on the xml file.</li>
<li>Set the DE values. I use <a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/" target="_blank">the previous article</a> examples.</li>
<li>Print the DE values set.</li>
<li>Pack the message.</li>
<li>Print the formatted ISO message. As you can see the result is the same with <a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/" target="_blank">the previous article</a> examples.</li>
</ol>
<h2 style="font-size: 1.5em;">Parse (unpack) ISO Message</h2>
<p>On this case it&#8217;s reversed. We have the ISO Message, and we need to see the DE values of it.<br />
Like the previous code this one also similar and should be easy to understand.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gnu.jimmod.iso8583.utility</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.ISOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.ISOMsg</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jpos.iso.packager.GenericPackager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ParseISOMessage <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ISOException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create Packager based on XML that contain DE type</span>
		GenericPackager packager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenericPackager<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;basic.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Print Input Data</span>
		<span style="color: #003399;">String</span> data <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DATA : &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Create ISO Message</span>
		ISOMsg isoMsg <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ISOMsg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">setPackager</span><span style="color: #009900;">&#40;</span>packager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isoMsg.<span style="color: #006633;">unpack</span><span style="color: #009900;">&#40;</span>data.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// print the DE list</span>
		logISOMsg<span style="color: #009900;">&#40;</span>isoMsg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> logISOMsg<span style="color: #009900;">&#40;</span>ISOMsg msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;----ISO MESSAGE-----&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;  MTI : &quot;</span> <span style="color: #339933;">+</span> msg.<span style="color: #006633;">getMTI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span>msg.<span style="color: #006633;">getMaxField</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #006633;">hasField</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;    Field-&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; : &quot;</span><span style="color: #339933;">+</span>msg.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ISOException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--------------------&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The output:</p>
<pre>DATA : 0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890
----ISO MESSAGE-----
  MTI : 0200
    Field-3 : 201234
    Field-4 : 000000010000
    Field-7 : 0110722180
    Field-11 : 123456
    Field-44 : A5DFGR
    Field-105 : ABCDEFGHIJ 1234567890
--------------------</pre>
<p>The program flow:</p>
<ol>
<li>Create ISO packager based on the xml file.</li>
<li>Set ISO Message.</li>
<li>Print the ISO Message.</li>
<li>Unpack the message.</li>
<li>Print the DE values. As you can see the result is correct, just like the DE set in first example.</li>
</ol>
<h2 style="font-size: 1.5em;"><strong>In the end</strong></h2>
<p>Ok, like always I hope I make it clear for you.<br />
This might not (yet) a tutorial to make you able the whole financial platform or a bank platform <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
But everyone need to start somewhere.</p>
<p>I see this code example as the implementation of <a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/">my previous article (ISO 8583 introduction)</a></p>
<p><a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/"></a>Just leave comment if you have questions.</p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners</a></li><li><a href='http://jimmod.com/blog/2007/11/simple-log4j-implementation/' rel='bookmark' title='Permanent Link: Simple Log4J implementation'>Simple Log4J implementation</a></li><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners</title>
		<link>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/</link>
		<comments>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 09:46:23 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[8583]]></category>
		<category><![CDATA[bank]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[financial]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[iso 8583]]></category>
		<category><![CDATA[jimmy]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[standard]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[transaction]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=209</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		ISO 8583 Tutorial article

Introduction for Beginners
Build and Parse ISO Message using JPOS library
????


Introduction
Lately I&#8217;ve handle several financial project that allow me to understand bank and financial transaction better.
All (or most?) financial transaction is using ISO 8583 standard, which at first I thought is a complicated standard. But after learn and see [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F07%2Fjimmys-blog-iso-8583-introduction-beginners-tutorial%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Introduction for Beginners" data-url="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><h2 style="font-size: 1.5em;"><strong style="font-weight: bold;">ISO 8583 Tutorial article</strong></h2>
<ul>
<li><a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/">Introduction for Beginners</a></li>
<li><a href="http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/">Build and Parse ISO Message using JPOS library</a></li>
<li>????</li>
</ul>
<ul></ul>
<h2><strong>Introduction</strong></h2>
<p>Lately I&#8217;ve handle several financial project that allow me to understand bank and financial transaction better.<br />
All (or most?) financial transaction is using ISO 8583 standard, which at first I thought is a complicated standard. But after learn and see how it implemented it&#8217;s not as complex as I thought.<br />
In this post I will try to explain (based on my experience <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  before I go deeper on the programming side.<br />
<span id="more-209"></span><br />
Although it&#8217;s a &#8217;standard&#8217; I see that&#8217;s many variant for the detail implementation of ISO 8583.</p>
<p>Financial transaction is communication between 2 system through socket connection.<br />
After connection established, each system can send message in ISO 8583 format which commonly will be request and the other system will response.<br />
From my experience the communication will be start with sign on and then the financial transactions.<br />
Periodically an echo message is send to make sure the other system is still alive.</p>
<p>If I break down the flow:</p>
<ol>
<li>System A open connection to System B (through specific IP and Port).</li>
<li>Connection established.</li>
<li>System A send Sign-On request message.</li>
<li>System B send Sign-on response message.</li>
<li>System A will start send Echo request message periodically (e.g every 1 minute).</li>
<li>System B will send Echo response message when receive Echo request message.</li>
<li>When financial transaction happen, System A will send Transaction request message.</li>
<li>Then System B will send Transaction response message.</li>
<li>If something wrong happen (usually timeout so System A didn&#8217;t get the response), System A will send Reversal request message to cancel the previous transaction.</li>
<li>System B will send Reversal response message.</li>
</ol>
<p>I hope my explaination give clear basic understanding about the flow.<br />
Next the question will be what&#8217;s this ISO 8583 message looks like.<br />
We can separate the message into 3 parts:</p>
<ul>
<li>Message Type Identifier</li>
<li>Bitmaps</li>
<li>Data Elements</li>
</ul>
<p style="text-align: center; "><strong> </strong></p>
<div id="attachment_216" class="wp-caption aligncenter" style="width: 310px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-structure.png"><img class="size-medium wp-image-216" title="ISO8583 - structure" src="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-structure-300x28.png" alt="ISO8583 - structure" width="300" height="28" /></a><p class="wp-caption-text">ISO8583 - structure</p></div>
<h2><strong>Message Type Identifier</strong></h2>
<p>Message Type Identifier or MTI is 4 digits numeric that describe the message type. It will explain the message function.<br />
Commonly used:<br />
- 02xx : Financial Message (e.g 0200 for request, 0210 for response)<br />
- 04xx : Reversal Message (e.g 0400 for request, 0410 for response)<br />
- 08xx : Network Management Message (e.g 0800 for request, 0810 for response)<br />
* I found more detail &amp; complete list at <a title="wikipedia" href="http://en.wikipedia.org/wiki/ISO_8583" target="_blank">wikipedia</a></p>
<h2><strong>Bitmaps</strong></h2>
<p>Bitmaps is field that contain information about which data element is presence or absence. Based on the variant it could be 16 hexadecimal characters.<br />
An example will make it clear.</p>
<p>The bitmap is:</p>
<p style="text-align: center;">B220000000100000</p>
<p>If we break down to binary (I hope you understand how to convert hexadecimal to binary:) :</p>
<p style="text-align: center;">1011001000100000000000000000000000000000000100000000000000000000</p>
<p>Since I&#8217;m nice <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  I create graphical illustration.</p>
<div id="attachment_211" class="wp-caption aligncenter" style="width: 310px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-bitmaps.png"><img class="size-medium wp-image-211" title="ISO8583 - bitmaps" src="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-bitmaps-300x8.png" alt="Bitmap sample" width="300" height="8" /></a><p class="wp-caption-text">Bitmap sample</p></div>
<p>You can see that in this bitmap it explain that data element in the message is 1, 3, 4, 7, 11.<br />
There&#8217;s special meaning of first bit of bitmap, if it has value of 1 that mean there&#8217;s secondary bitmap.<br />
And what the hell is this secondary bitmap?<br />
Since 16 hexadecimal characters will can only contain info of 64 data element, some transactions contain data element number 64 &#8211; 128. That mean the 16 hexadecimal characters is not sufficient.<br />
With set the first bit to &#8216;1&#8242; that will inform there&#8217;s additional bitmap, which is another 16 hexadecimal characters.<br />
So in this case the full bitmap example should be:<br />
B220000000100000<strong>0000000000800000</strong><br />
Convert to binary:<br />
1011001000100000000000000000000000000000000100000000000000000000<strong>0000000000000000000000000000000000000000100000000000000000000000</strong><br />
From the bitmap, data element presence in the message : 3, 4, 7, 11, 105.</p>
<div id="attachment_212" class="wp-caption aligncenter" style="width: 310px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-bitmaps-2.png"><img class="size-medium wp-image-212" title="ISO8583 - bitmaps - 2" src="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-bitmaps-2-300x20.png" alt="Sample Bitmap complete" width="300" height="20" /></a><p class="wp-caption-text">Sample Bitmap complete</p></div>
<h2>Data Elements</h2>
<p>Data Elements is the essense of the whole ISO message, contain information about the transaction (transaction type, amount, customer id, etc).<br />
Each data element have their on format, attribute and length.<br />
Each data element number also have standard purpose, for example DE #4 is transaction amount.<br />
I will explain based on the example above, since this is only introduction I don&#8217;t want to confuse beginner reader. In <a href="http://en.wikipedia.org/wiki/ISO_8583#Data_elements" target="_blank">wikipedia </a> there&#8217;s full list.<br />
For our examples, the data element list:</p>
<ul>
<li>#3 &#8211; Processing code &#8211; n 6</li>
<li>#4 &#8211; Transaction amount &#8211; n 12</li>
<li>#7 &#8211; Transmission date &amp; time &#8211; n 10</li>
<li>#11 &#8211; Systems trace audit number &#8211; n 6</li>
<li>#44 &#8211; Additional response data &#8211; an ..25</li>
<li>#105 &#8211; Reserved for ISO use &#8211; ans &#8230;999</li>
</ul>
<p>To make it practical let&#8217;s just use example.<br />
We want to send :</p>
<ul>
<li>DE #3 : 201234</li>
<li>DE #4 : 10000</li>
<li>DE #7 : 1107221830</li>
<li>DE #11 : 123456</li>
<li>DE #44 : A5DFGR</li>
<li>DE #105 : ABCDEFGHIJ 1234567890</li>
</ul>
<p>Using above value, the data in data elements :</p>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 310px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-de2.png"><img class="size-medium wp-image-238" title="ISO8583 - de" src="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-de2-300x77.png" alt="ISO8583 - de" width="300" height="77" /></a><p class="wp-caption-text">ISO8583 - de</p></div>
<p style="text-align: center;">
<p>Based on the type each value will be formatted.</p>
<ul>
<li>a : alpha (including blanks)</li>
<li>n : numeric value</li>
<li>s : special characters</li>
<li> x (no dot) : length is x (fixed)</li>
<li>.x (one dot) :  max length is x (1 digit in front as length info)</li>
<li>..xx (two dot) :  max length is xx (2 digit in front as length info)</li>
<li>&#8230;xxx (three dot) :  max length is xxx (3 digit in front as length info)</li>
</ul>
<h2><strong>ISO Message</strong></h2>
<p>From above examples the whole ISO message will be :</p>
<p style="text-align: center;">0200B2200000001000000000000000800000201234000000010000110722183012345606A5DFGR021ABCDEFGHIJ   1234567890</p>
<p style="text-align: center;"><a href="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-full1.png"><img class="aligncenter size-full wp-image-239" title="ISO8583 - full" src="http://jimmod.com/blog/wp-content/uploads/2011/07/ISO8583-full1.png" alt="ISO8583 - full" width="983" height="88" /></a></p>
<p style="text-align: center;">
<h2>Conclusion</h2>
<p>Ok. This article already long enough <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Actually I always prefer short article, but on this case it&#8217;s cannot be to short.<br />
Anyway, I hope this article is clear enough for you.</p>
<p>Like always, just drop question in the comment if you confused.</p>
<p>Next I will write article about implementing ISO 8583 using JPOS library.</p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-introduction-beginners-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jimmy&#8217;s Blog &#8211; Slide Number Puzzle Game with Echo2 Framework</title>
		<link>http://jimmod.com/blog/2011/02/jimmys-blog-slide-number-puzzle-game-with-echo2-framework/</link>
		<comments>http://jimmod.com/blog/2011/02/jimmys-blog-slide-number-puzzle-game-with-echo2-framework/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 06:12:32 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[echo2]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[puzzle]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=193</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		I&#8217;m checking Echo2 framework these couple days and try to make a simple game just to get to know the framework better.
Since I&#8217;m not a JavaScript expert it&#8217;s good to know that there&#8217;s framework that I can use to create AJAX web app with desktop feel easily.
The game is about re-ordering [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li><li><a href='http://jimmod.com/blog/2008/07/java-application-make-sure-only-singleone-instance-running-with-file-lock-ampampampampamp-shutdownhook/' rel='bookmark' title='Permanent Link: Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook'>Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F02%2Fjimmys-blog-slide-number-puzzle-game-with-echo2-framework%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/02/jimmys-blog-slide-number-puzzle-game-with-echo2-framework/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Jimmy&#8217;s Blog &#8211; Slide Number Puzzle Game with Echo2 Framework" data-url="http://jimmod.com/blog/2011/02/jimmys-blog-slide-number-puzzle-game-with-echo2-framework/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>I&#8217;m checking Echo2 framework these couple days and try to make a simple game just to get to know the framework better.<br />
Since I&#8217;m not a JavaScript expert it&#8217;s good to know that there&#8217;s framework that I can use to create AJAX web app with desktop feel easily.<br />
The game is about re-ordering number by moving number to the empty space. It&#8217;s simple and fun, this sample is hardcoded to only support 3&#215;3 size.</p>
<p>I assume you know Java, JSP, Servlet basics.<br />
Download Echo 2 from : <a href="http://echo.nextapp.com/site/echo2/download">Echo2 Website</a><br />
I personally use Eclipse for my IDE.</p>
<p>Step by step:<br />
<span id="more-193"></span><br />
<strong>1. Create web project with your IDE, this should set up your project structure based on IDE you used.</strong><br />
<strong>2. Add Echo 2 library to your build path (Echo2_App.jar, Echo2_WebContainer.jar, Echo2_WebRender.jar).</strong><br />
<strong>3. Add servlet mapping in your web.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NumberGameServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NumberGameServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>gnu.jimmy.java.echo2.numbergame.NumberGameServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NumberGameServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/game<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>4. Create NumberGameServlet that extend WebContainerServlet. This class will only return the application instance to be displayed to user</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gnu.jimmy.java.echo2.numbergame</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.ApplicationInstance</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.webcontainer.WebContainerServlet</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class NumberGameServlet
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NumberGameServlet <span style="color: #000000; font-weight: bold;">extends</span> WebContainerServlet <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> ApplicationInstance newApplicationInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> NumberGameApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>5. Create class NumberGameApp that extend ApplicationInstance.</strong><br />
This is the core of the game, the game code is simple &#8211; we store the number position data and allow user to switch between number with button up/down/left/right or click the button near the empty one.<br />
After that there will be checking if the number is order properly.<br />
There&#8217;s also button to random the numbers, this will trigger up/down/left/right movements.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gnu.jimmy.java.echo2.numbergame</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.ApplicationInstance</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Color</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.ContentPane</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Extent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Grid</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.ImageReference</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Label</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.ResourceImageReference</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.Window</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.WindowPane</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.event.ActionEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.event.ActionListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nextapp.echo2.app.layout.GridLayoutData</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NumberGameApp <span style="color: #000000; font-weight: bold;">extends</span> ApplicationInstance <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">ActionListener</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Window</span> window<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> ContentPane contentPane<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Grid container<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> numbers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> random<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> up<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> left<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> right<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> down<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> WindowPane pane<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Label</span> paneLabel<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> numberData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> numberPos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Window</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		window <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Window</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		contentPane <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ContentPane<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		window.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span>contentPane<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		container <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Grid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">setSize</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		contentPane.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>numbers.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ImageReference image <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			numbers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span>image<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			GridLayoutData layoutData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GridLayoutData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			layoutData.<span style="color: #006633;">setBackground</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span>0xffffcf<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			numbers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">setLayoutData</span><span style="color: #009900;">&#40;</span>layoutData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			numbers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			numberData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
			numberPos<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		random <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/b_random.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		random.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		up <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/b_up.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		up.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		down <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/b_down.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		down.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		left <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/b_left.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		left.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		right <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/b_right.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		right.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		pane <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WindowPane<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Message&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> Extent<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Extent<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		paneLabel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		pane.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>paneLabel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		pane.<span style="color: #006633;">setModal</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		imageRefresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> window<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> switchNumber<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> n1, <span style="color: #000066; font-weight: bold;">int</span> n2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Switching : &quot;</span> <span style="color: #339933;">+</span> n1 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; - &quot;</span> <span style="color: #339933;">+</span> n2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> t <span style="color: #339933;">=</span> numberData<span style="color: #009900;">&#91;</span>n1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		numberData<span style="color: #009900;">&#91;</span>n1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> numberData<span style="color: #009900;">&#91;</span>n2<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		numberData<span style="color: #009900;">&#91;</span>n2<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span>
		numberPos<span style="color: #009900;">&#91;</span>numberData<span style="color: #009900;">&#91;</span>n1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>n1<span style="color: #339933;">;</span>
		numberPos<span style="color: #009900;">&#91;</span>numberData<span style="color: #009900;">&#91;</span>n2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>n2<span style="color: #339933;">;</span>
		imageRefresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> imageRefresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		container.<span style="color: #006633;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>numbers.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>numbers<span style="color: #009900;">&#91;</span>numberData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		ImageReference imgEmpty <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ResourceImageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/empty.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>up<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>left<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>down<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		container.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>imgEmpty<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actionPerformed<span style="color: #009900;">&#40;</span><span style="color: #003399;">ActionEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> numberPress<span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> up<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			moveUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> down<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			moveDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> left<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			moveLeft<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			moveRight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> random<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>total<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">int</span> move <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>move<span style="color: #339933;">%</span>4 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					moveUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>move<span style="color: #339933;">%</span>4 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					moveDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>move<span style="color: #339933;">%</span>4 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					moveLeft<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>move<span style="color: #339933;">%</span>4 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					moveRight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> numbers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					 numberPress<span style="color: #339933;">=</span>numberPos<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				 <span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPress<span style="color: #339933;">==</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				moveDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPress<span style="color: #339933;">==</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				moveUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPress<span style="color: #339933;">==</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				moveRight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPress<span style="color: #339933;">==</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				moveLeft<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>checking<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			contentPane.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>pane<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			pane.<span style="color: #006633;">setPositionX</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Extent<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			pane.<span style="color: #006633;">setPositionY</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Extent<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			paneLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Puzzle Finished&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			paneLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> moveUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			switchNumber<span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span>, numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> moveDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;=</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			switchNumber<span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span>, numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> moveLeft<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">%</span>3 <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			switchNumber<span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span>, numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> moveRight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">%</span>3 <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			switchNumber<span style="color: #009900;">&#40;</span>numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span>, numberPos<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> checking<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> match<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>numberData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				match<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> match<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Screenshot:<br />
<div id="attachment_198" class="wp-caption aligncenter" style="width: 149px"><a href="http://jimmod.com/blog/wp-content/uploads/2011/02/numbergame.png"><img src="http://jimmod.com/blog/wp-content/uploads/2011/02/numbergame-139x300.png" alt="Game Screenshot" title="numbergame" width="139" height="300" class="size-medium wp-image-198" /></a><p class="wp-caption-text">Game Screenshot</p></div></p>
<p>Code logic:<br />
- I create all number using button and add action listener on it.<br />
- On number button clicked it will check if the number is next to empty space, if yes it will switch it.<br />
- Random button will random the movement from 10-110 movement, so the numbers will be disordered but for sure it can be re-ordered.<br />
- Arrow will make empty space switch with number next to it<br />
- After every movement it will check if the numbers already ordered properly</p>
<p>Any question just drop a comment <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li><li><a href='http://jimmod.com/blog/2008/07/java-application-make-sure-only-singleone-instance-running-with-file-lock-ampampampampamp-shutdownhook/' rel='bookmark' title='Permanent Link: Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook'>Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/02/jimmys-blog-slide-number-puzzle-game-with-echo2-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jimmy&#8217;s Blog &#8211; Send &amp; Receiving SMS on specific Port with J2ME Application</title>
		<link>http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/</link>
		<comments>http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 04:19:58 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[jsr-120]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[receive]]></category>
		<category><![CDATA[send]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[wma]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=180</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		It’s been a while since I write an article, personal and work have been taken my time much lately.
What I will write is not a new things, maybe a lot of article already write this kind of feature. But yesterday I see this kind of project request in freelancer.com so I [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2008/07/java-application-make-sure-only-singleone-instance-running-with-file-lock-ampampampampamp-shutdownhook/' rel='bookmark' title='Permanent Link: Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook'>Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2011%2F02%2Fjimmys-blog-send-receiving-on-specific-port-with-j2me-application%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application" data-url="http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>It’s been a while since I write an article, personal and work have been taken my time much lately.</p>
<p>What I will write is not a new things, maybe a lot of article already write this kind of feature. But yesterday I see this kind of project request in freelancer.com so I decide to create a simple sample and write an article about it.</p>
<p>Java Mobile (J2ME) application have a capability to send or receive SMS, but the phone need to support JSR-120 (Wireless Messaging API – WMA 1.0) or JSR-205 (WMA 2.0)<br />
How to check if the phone is supporting this? Easy way if the phone’s brand website. For example for Nokia E72 we can see the technical specifications at <a href="http://developer.nokia.com/Devices/Device_specifications/E72/">http://developer.nokia.com/Devices/Device_specifications/E72/</a><br />
If your phone doesn’t have WMA library the application will prompt error (the error can be different from one phone to another)<br />
<span id="more-180"></span><br />
Sending SMS with J2ME is simple, one thing that programmer can forget is about putting it on another thread. To prevent a dead lock on sending, we need to create a thread to execute the sending.<br />
Another thing is we can specifically send the SMS to specific port, which is important in this J2ME case. Because in J2ME we can only listen SMS on specific port (cannot on default port).</p>
<p>The sample is simple, with basic J2ME programming skill you should able to understand it. If you don’t just drop me a comment <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Source code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">poc.jwork.j2me.sendrecvsms</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.io.Connector</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Command</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.CommandListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Display</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Displayable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Form</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.TextField</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDletStateChangeException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.MessageConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.MessageListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.TextMessage</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SMSSender <span style="color: #000000; font-weight: bold;">extends</span> MIDlet <span style="color: #000000; font-weight: bold;">implements</span> CommandListener <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Form formSender <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SMS Sender&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">TextField</span> tfDestination <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Destination&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #003399;">TextField</span>.<span style="color: #006633;">PHONENUMBER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">TextField</span> tfPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Port&quot;</span>, <span style="color: #0000ff;">&quot;5000&quot;</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #003399;">TextField</span>.<span style="color: #006633;">NUMERIC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">TextField</span> tfMessage <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Message&quot;</span>, <span style="color: #0000ff;">&quot;message&quot;</span>, <span style="color: #cc66cc;">150</span>, <span style="color: #003399;">TextField</span>.<span style="color: #006633;">ANY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdSend <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Send&quot;</span>, Command.<span style="color: #006633;">OK</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdExit <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Exit&quot;</span>, Command.<span style="color: #006633;">EXIT</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> SMSSender<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		formSender.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>tfDestination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formSender.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>tfPort<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formSender.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>tfMessage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formSender.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdSend<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formSender.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formSender.<span style="color: #006633;">setCommandListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		display <span style="color: #339933;">=</span> Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> destroyApp<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> pauseApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
		display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>formSender<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> commandAction<span style="color: #009900;">&#40;</span>Command c, Displayable d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">==</span>cmdSend<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			SendMessage.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>tfDestination.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, tfPort.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, tfMessage.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">==</span>cmdExit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			notifyDestroyed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SendMessage <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> destination, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> port, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #003399;">Thread</span> thread <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				MessageConnection msgConnection<span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
					msgConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MessageConnection<span style="color: #009900;">&#41;</span>Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sms://&quot;</span><span style="color: #339933;">+</span>destination<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					TextMessage textMessage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextMessage<span style="color: #009900;">&#41;</span>msgConnection.<span style="color: #006633;">newMessage</span><span style="color: #009900;">&#40;</span>
							MessageConnection.<span style="color: #006633;">TEXT_MESSAGE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					textMessage.<span style="color: #006633;">setPayloadText</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					msgConnection.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span>textMessage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					msgConnection.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		thread.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">poc.jwork.j2me.sendrecvsms</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InterruptedIOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.io.Connector</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Command</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.CommandListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Display</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Displayable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Form</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.TextField</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDletStateChangeException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.Message</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.MessageConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.MessageListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.wireless.messaging.TextMessage</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SMSReceiver <span style="color: #000000; font-weight: bold;">extends</span> MIDlet <span style="color: #000000; font-weight: bold;">implements</span> CommandListener, MessageListener <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Form formReceiver <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SMS Receiver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">TextField</span> tfPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Port&quot;</span>, <span style="color: #0000ff;">&quot;5000&quot;</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #003399;">TextField</span>.<span style="color: #006633;">NUMERIC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdListen <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Listen&quot;</span>, Command.<span style="color: #006633;">OK</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdExit <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Exit&quot;</span>, Command.<span style="color: #006633;">EXIT</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> SMSReceiver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		formReceiver.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>tfPort<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formReceiver.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdListen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formReceiver.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formReceiver.<span style="color: #006633;">setCommandListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		display <span style="color: #339933;">=</span> Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> destroyApp<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> unconditional<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> pauseApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
		display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>formReceiver<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> commandAction<span style="color: #009900;">&#40;</span>Command c, Displayable d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">==</span>cmdListen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ListenSMS sms <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ListenSMS<span style="color: #009900;">&#40;</span>tfPort.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			sms.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			formReceiver.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdListen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">==</span>cmdExit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			notifyDestroyed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> notifyIncomingMessage<span style="color: #009900;">&#40;</span>MessageConnection conn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Message message<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			message <span style="color: #339933;">=</span> conn.<span style="color: #006633;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>message <span style="color: #000000; font-weight: bold;">instanceof</span> TextMessage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				TextMessage tMessage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextMessage<span style="color: #009900;">&#41;</span>message<span style="color: #339933;">;</span>
				formReceiver.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Message received : &quot;</span><span style="color: #339933;">+</span>tMessage.<span style="color: #006633;">getPayloadText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				formReceiver.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unknown Message received<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedIOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ListenSMS <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Thread</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> MessageConnection msgConnection<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> MessageListener listener<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> port<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ListenSMS<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> port, MessageListener listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">port</span> <span style="color: #339933;">=</span> port<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">listener</span> <span style="color: #339933;">=</span> listener<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			msgConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MessageConnection<span style="color: #009900;">&#41;</span>Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sms://:&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			msgConnection.<span style="color: #006633;">setMessageListener</span><span style="color: #009900;">&#40;</span>listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Screenshot:</strong><br />
<div id="attachment_183" class="wp-caption aligncenter" style="width: 233px"><img src="http://jimmod.com/blog/wp-content/uploads/2011/02/smssender-223x300.png" alt="SMS Sender in simulator" title="smssender" width="223" height="300" class="size-medium wp-image-183" /><p class="wp-caption-text">SMS Sender in simulator</p></div><br />
<div id="attachment_184" class="wp-caption aligncenter" style="width: 251px"><img src="http://jimmod.com/blog/wp-content/uploads/2011/02/smsreceiver-241x300.png" alt="SMS Reveiver in Simulator" title="smsreceiver" width="241" height="300" class="size-medium wp-image-184" /><p class="wp-caption-text">SMS Reveiver in Simulator</p></div></p>
<p><strong>Build:</strong><br />
<a href='http://jimmod.com/blog/wp-content/uploads/2011/02/POC_SendRecvSMS.jad'>JAD FILE</a><br />
<a href='http://jimmod.com/blog/wp-content/uploads/2011/02/POC_SendRecvSMS.jar'>JAR FILE</a></p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2008/07/java-application-make-sure-only-singleone-instance-running-with-file-lock-ampampampampamp-shutdownhook/' rel='bookmark' title='Permanent Link: Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook'>Java Application &#8211; Make sure only single/one instance running &#8211; with File Lock and ShutdownHook</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion</title>
		<link>http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/</link>
		<comments>http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 04:18:18 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[distortion]]></category>
		<category><![CDATA[fixing]]></category>
		<category><![CDATA[flicker]]></category>
		<category><![CDATA[lucid]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[Solving]]></category>
		<category><![CDATA[ubuntu 10.04]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=174</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		
I experiencing random screen distortion &#38; flicker after upgrading to Ubuntu 10.04, I&#8217;m using Acer Notebook.
After searching in internet, there&#8217;s many forum thread &#38; bug report discuss about this but mostly they have different hardware.
Finally I tried this method and no flickering so far.
What I do is I change my grub [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2009/06/solving-failed-starting-mysql-service-with-non-default-datadir-ubuntu/' rel='bookmark' title='Permanent Link: Solving failed starting mysql service with non default datadir (Ubuntu)'>Solving failed starting mysql service with non default datadir (Ubuntu)</a></li><li><a href='http://jimmod.com/blog/2009/06/solving-pidgin-cannot-connect-ym/' rel='bookmark' title='Permanent Link: Solving Pidgin cannot connect to Yahoo Messenger (YM)'>Solving Pidgin cannot connect to Yahoo Messenger (YM)</a></li><li><a href='http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/' rel='bookmark' title='Permanent Link: Updating Pidgin to latest version in Ubuntu'>Updating Pidgin to latest version in Ubuntu</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2010%2F06%2Fsolving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion" data-url="http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } --></p>
<p style="margin-bottom: 0in;">I experiencing random screen distortion &amp; flicker after upgrading to Ubuntu 10.04, I&#8217;m using Acer Notebook.<br />
After searching in internet, there&#8217;s many forum thread &amp; bug report discuss about this but mostly they have different hardware.<br />
Finally I tried this method and no flickering so far.</p>
<p style="margin-bottom: 0in;">What I do is I change my grub configuration, adding kernel parameter “i915.powersave=0”.</p>
<p style="margin-bottom: 0in;">For Linux expert probably this is not an issue, so I dedicate this step for the newbies like <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ol>
<li>What I do is I modify the grub configuration which is located on /boot/grub/grub.cfg (backup before you edit it)</li>
<li>Because the access right is set to read only, let&#8217;s change it so the owner can modify it.<br />
<em>&gt; sudo chmod -c u+w /boot/grub/grub.cfg</em></li>
<li>Use vi or your other prefered editor to edit it.<br />
&gt; sudo vim /boot/grub/grub.cfg</li>
<li>Locate the menuentry of your Linux. Example:<br />
<em>menuentry &#8216;Ubuntu, with Linux 2.6.32-22-generic&#8217; &#8211;class ubuntu &#8211;class gnu-linux &#8211;class gnu &#8211;class os {<br />
recordfail<br />
insmod ext2<br />
set root=&#8217;(hd0,4)&#8217;<br />
search &#8211;no-floppy &#8211;fs-uuid &#8211;set xxx-xxx-xxx</em><br />
<em><strong> linux	/vmlinuz-2.6.32-22-generic root=UUID=xx-xx-xxx-x-xx ro quiet splash</strong><br />
initrd	/initrd.img-2.6.32-22-generic<br />
}</em></li>
<li>Add “i915.powersave=0” to the linux kernel line as parameter. It will become:<br />
menuentry &#8216;Ubuntu, with Linux 2.6.32-22-generic&#8217; &#8211;class ubuntu &#8211;class gnu-linux &#8211;class gnu &#8211;class os {<br />
recordfail<br />
insmod ext2<br />
set root=&#8217;(hd0,4)&#8217;<br />
<em> search &#8211;no-floppy &#8211;fs-uuid &#8211;set xxx-xxx-xxx</em><br />
<em><strong>linux	/vmlinuz-2.6.32-22-generic root=UUID=xx-xx-xxx-x-xx ro </strong></em><strong>i915.powersave=0</strong><em><strong> quiet splash</strong></em><br />
initrd	/initrd.img-2.6.32-22-generic<br />
}</li>
<li>Save &amp; restart to check if you still experiencing screen flicker</li>
</ol>
<p>That&#8217;s it <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Hope it can work on other Notebook/PC</p>
<p>*Additional tips from tipster2010:</p>
<blockquote><p>Thanks for this tip. It will work but after some time, flickering returns. I think I know the reason why:<br />
1. Remember to turn off all screen saver and any power saving feature of your laptop after you did this.<br />
2. Any time you change the theme of your desktop, the screensaver and power saving feature sometimes go back to default so you may need to manually change them again.</p></blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 549px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thanks for this tip. It will work but after some time, flickering returns. I think I know the reason why:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 549px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1. Remember to turn off all screen saver and any power saving feature of your laptop after you did this.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 549px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2. Any time you change the theme of your desktop, the screensaver and power saving feature sometimes go back to default so you may need to manually change them again</div>
<p style="margin-bottom: 0in;">


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2009/06/solving-failed-starting-mysql-service-with-non-default-datadir-ubuntu/' rel='bookmark' title='Permanent Link: Solving failed starting mysql service with non default datadir (Ubuntu)'>Solving failed starting mysql service with non default datadir (Ubuntu)</a></li><li><a href='http://jimmod.com/blog/2009/06/solving-pidgin-cannot-connect-ym/' rel='bookmark' title='Permanent Link: Solving Pidgin cannot connect to Yahoo Messenger (YM)'>Solving Pidgin cannot connect to Yahoo Messenger (YM)</a></li><li><a href='http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/' rel='bookmark' title='Permanent Link: Updating Pidgin to latest version in Ubuntu'>Updating Pidgin to latest version in Ubuntu</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Basic LWUIT tutorial/sample with Eclipse Pulsar</title>
		<link>http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/</link>
		<comments>http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 17:31:41 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[java me]]></category>
		<category><![CDATA[label]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[LWUIT]]></category>
		<category><![CDATA[Pulsar]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[transition]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ui framework]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=158</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		I was really want to try LWUIT since several months ago. It&#8217;s look promising and it&#8217;s developed by SUN so I think every Java ME developer should take a look on this technology.
I&#8217;m also still new in LWUIT so there won&#8217;t be a lot that I can share for now, but [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2010%2F04%2Fbasic-lwuit-tutorial-with-eclipse-pulsar%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Basic LWUIT tutorial/sample with Eclipse Pulsar" data-url="http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>I was really want to try LWUIT since several months ago. It&#8217;s look promising and it&#8217;s developed by SUN so I think every Java ME developer should take a look on this technology.<br />
I&#8217;m also still new in LWUIT so there won&#8217;t be a lot that I can share for now, but at least I will show you a basic demonstration of how to use Form, Label, Command, and 3D Form transition (sound cool huh :p)</p>
<p><strong>REQUIREMENT</strong></p>
<p>What you need:</p>
<ol>
<li> <a href="https://lwuit.dev.java.net/">LWUIT</a></li>
<li><a href="http://www.eclipse.org/pulsar/">Eclipse Pulsa</a></li>
<li>Emulator like <a href="http://java.sun.com/products/sjwtoolkit/">Sun WTK </a></li>
<li>Know basic Java ME programming <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <span id="more-158"></span></li>
</ol>
<p><strong>CONFIGURE ECLIPSE</strong></p>
<p>First you need to setup your emulator in Eclipse.<br />
Run your Eclipse and select at the menu : Window &#8211; Preferences<br />
Select : Java ME &#8211; Device Management &#8211; click Import<br />
Then browse to your emulator folder, it will scan and give you option to add it to your device list.</p>
<div id="attachment_159" class="wp-caption aligncenter" style="width: 160px"><a href="http://jimmod.com/blog/wp-content/uploads/2010/04/Pulsar_WTK.jpg"><img class="size-thumbnail wp-image-159 " title="Eclipse Pulsar Device Management" src="http://jimmod.com/blog/wp-content/uploads/2010/04/Pulsar_WTK-150x150.jpg" alt="Eclipse Pulsar Device Management" width="150" height="150" /></a><p class="wp-caption-text">Eclipse Pulsar Device Management</p></div>
<p>*I found that the automatic javadoc folder detection for each jar library is not all correct (I&#8217;m using Ubuntu 9.04, WTK 2.5.1)</p>
<p><strong>CREATE NEW MIDlet PROJECT &amp; CONFIGURE</strong></p>
<p>Ok, now we ready to create the new project.<br />
I assume you already know how to use Eclipse properly, create a new MIDlet Project there you will select your default emulator you want to use in the project, MIDP &#8211; CLDC version, etc.<br />
After the new project created we gonna add the LWUIT library to the project.<br />
Right click on the project (at package explorer) and select Properties.<br />
Select &#8216;Java Build Path&#8217; and tab &#8216;Libraries&#8217; then click &#8216;Add External Jars&#8217; and browse to select where your LWUIT jar is. (It will be on the lib folder where you extract you LWUIT zip)</p>
<div id="attachment_160" class="wp-caption aligncenter" style="width: 160px"><a href="http://jimmod.com/blog/wp-content/uploads/2010/04/project_properties.jpg"><img class="size-thumbnail wp-image-160 " title="MIDlet Project Properties" src="http://jimmod.com/blog/wp-content/uploads/2010/04/project_properties-150x150.jpg" alt="MIDlet Project Properties" width="150" height="150" /></a><p class="wp-caption-text">MIDlet Project Properties</p></div>
<p>You will see the LWUIT.jar shown.<br />
Select tab &#8216;Order and Export&#8217;, check the LWUIT.jar library so it will be included in our application jar.</p>
<div id="attachment_161" class="wp-caption aligncenter" style="width: 160px"><a href="http://jimmod.com/blog/wp-content/uploads/2010/04/Properties-Order-and-Export.png"><img class="size-thumbnail wp-image-161 " title="Pulsa MIDlet project order and export" src="http://jimmod.com/blog/wp-content/uploads/2010/04/Properties-Order-and-Export-150x150.png" alt="Pulsa MIDlet project order and export" width="150" height="150" /></a><p class="wp-caption-text">Pulsa MIDlet project order and export</p></div>
<p>One of the cool thing about LWUIT is theme feature, you can see there&#8217;s ResourceEditor in LWUIT&#8217;s &#8216;util&#8217; folder it&#8217;s for editing theme.<br />
Let&#8217;s use default theme from the package. Copy file that located at ./LWUITDemo/src/LWUITtheme.res to our project &#8216;res&#8217;  folder (you can drag &#8216;n drop it to Eclipse).</p>
<p><strong>THE CODING</strong></p>
<p>Now we finally get to real coding.<br />
Add a new MIDlet to the project. In my example I will create BasicForm Class:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gnu.jimmy.blog.lwuit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.MIDletStateChangeException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.Command</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.Display</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.Form</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.Label</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.animations.CommonTransitions</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.animations.Transition3D</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.events.ActionEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.events.ActionListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.layouts.BorderLayout</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.layouts.BoxLayout</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.plaf.UIManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.lwuit.util.Resources</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BasicForm <span style="color: #000000; font-weight: bold;">extends</span> MIDlet <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">ActionListener</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Form form1<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Form form2<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdRotate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Rotate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdSlide <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Slide&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdExit <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Exit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> BasicForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Initialize the LWUIT</span>
		Display.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Load the Theme</span>
		Resources r<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			r <span style="color: #339933;">=</span> Resources.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/LWUITtheme.res&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">UIManager</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
			<span style="color: #006633;">setThemeProps</span><span style="color: #009900;">&#40;</span>r.<span style="color: #006633;">getTheme</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LWUITDefault&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Setup Form 1</span>
		form1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Form 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BorderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">NORTH</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;My First Form&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">WEST</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WEST&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">CENTER</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CENTER&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">EAST</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EAST&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">SOUTH</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Click Rotate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdRotate<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">addCommandListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form1.<span style="color: #006633;">setTransitionInAnimator</span><span style="color: #009900;">&#40;</span>CommonTransitions.<span style="color: #006633;">createSlide</span><span style="color: #009900;">&#40;</span>CommonTransitions.<span style="color: #006633;">SLIDE_HORIZONTAL</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Setup Form 2</span>
		form2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Form 2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BoxLayout</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BoxLayout</span>.<span style="color: #006633;">Y_AXIS</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #000066; font-weight: bold;">null</span>,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;This is the second Form&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdSlide<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">addCommandListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form2.<span style="color: #006633;">setTransitionInAnimator</span><span style="color: #009900;">&#40;</span>Transition3D.<span style="color: #006633;">createCube</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		form1.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actionPerformed<span style="color: #009900;">&#40;</span><span style="color: #003399;">ActionEvent</span> evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//check which command cliked</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #006633;">getCommand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>cmdExit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			notifyDestroyed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #006633;">getCommand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>cmdRotate<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			form2.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #006633;">getCommand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>cmdSlide<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			form1.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> destroyApp<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> unconditional<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> pauseApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Try to run the class.<br />
It should display a form and when you click the left softkey change to the second form with cube rotate effect.<br />
When you click the left softkey again it will go back to first form with slide effect.</p>
<div id="attachment_166" class="wp-caption aligncenter" style="width: 258px"><img class="size-full wp-image-166" title="LWUIT sample" src="http://jimmod.com/blog/wp-content/uploads/2010/04/sample.jpg" alt="LWUIT sample" width="248" height="327" /><p class="wp-caption-text">LWUIT sample</p></div>
<p><strong>NOTE</strong><br />
* all  UI classes are from package com.sun.lwuit don&#8217;t import the WTK default.<br />
* Display.init function (the one I put in constructor) needed to execute first before initializing Forms<br />
* Theme need to be load first before initializing Forms<br />
* Transition3D will require M3G, so if you want to test it on real phone make sure your phone support it. If not you can just change the Transition3D to CommonTransition.</p>
<p><strong>ENDING</strong></p>
<p>If you have prompt to follow the tutorial just drop me a comment here.</p>
<p>Cheers <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li><li><a href='http://jimmod.com/blog/2011/07/jimmys-blog-iso-8583-tutorial-build-and-parse-iso-message-using-jpos-library/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library'>Jimmy&#8217;s Blog &#8211; ISO 8583 Tutorial &#8211; Build and Parse ISO Message using JPOS library</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>Updating Pidgin to latest version in Ubuntu</title>
		<link>http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/</link>
		<comments>http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 15:20:39 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[2.6]]></category>
		<category><![CDATA[latest]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[ppa]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[yahoo messenger]]></category>
		<category><![CDATA[ym problem]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=148</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		Since the latest pidgin not available in 9.04 repository you need to setup PPA just like instruction in pidgin website. My instruction here is the same although the command a bit different. This will also solve cannot connect to Yahoo Messenger issue.

run 	this command in console to open vim editor :

sudo vim [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2009/06/solving-pidgin-cannot-connect-ym/' rel='bookmark' title='Permanent Link: Solving Pidgin cannot connect to Yahoo Messenger (YM)'>Solving Pidgin cannot connect to Yahoo Messenger (YM)</a></li><li><a href='http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/' rel='bookmark' title='Permanent Link: Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion'>Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2010%2F03%2Fupdating-pidgin-to-latest-version-in-ubuntu%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Updating Pidgin to latest version in Ubuntu" data-url="http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>Since the latest pidgin not available in 9.04 repository you need to setup PPA just like instruction in <a href="http://www.pidgin.im/download/ubuntu/">pidgin website</a>. My instruction here is the same although the command a bit different. This will also solve cannot connect to Yahoo Messenger issue.<span id="more-148"></span></p>
<ul>
<li>run 	this command in console to open vim editor :</li>
</ul>
<blockquote><p>sudo vim /etc/apt/sources.list.d/pidgin-ppa.list</p></blockquote>
<blockquote><p>(if you not familiar with vim use gnome editor with command : <em>sudo gedit /etc/apt/sources.list.d/pidgin-ppa.list</em>)<br />
*since it&#8217;s using <em>sudo</em> command you will requested to enter your password to enter root mode)</p></blockquote>
<ul>
<li>Add 	this line:</li>
</ul>
<blockquote><p>deb http://ppa.launchpad.net/pidgin-developers/ppa/ubuntu <strong>jaunty</strong> main</p>
<p>*I bold the <strong>jaunty</strong> since it will depends on your ubuntu version (8.10=intrepid, 9.04=jaunty, 9.10=karmic). If you not sure run this command : lsb_release &#8211;short &#8211;codename</p>
<p>* It will print out your ubuntu release codename</p>
<p>If you&#8217;re in Indonesia you can put UGM repository (instead the above line):</p>
<p>deb ftp://repo.ugm.ac.id/ppa.launchpad.net/pidgin-developers/ <strong>jaunty </strong> main</p></blockquote>
<ul>
<li>Save 	the file. Since you don&#8217;t have the file (/etc/apt/sources.list.d/pidgin-ppa.list) it will create new file when you save it.</li>
</ul>
<ul>
<li>Next 	you also need to download pidgin public key by executing this 	command:sudo 	apt-key adv &#8211;recv-keys &#8211;keyserver keyserver.ubuntu.com 	67265eb522bdd6b1c69e66ed7fb8bee0a1f196a8</li>
<li>Then 	open your <strong>Synaptic 	Package Manager</strong> and click Reload</li>
<li>Write &#8216;pidgin&#8217; in your quick search textbox and see if latest pidgin 	version is 2.6.x</li>
</ul>
<p style="text-align: center;">
<div id="attachment_149" class="wp-caption alignnone" style="width: 160px"><img class="size-thumbnail wp-image-149" title="Screenshot-Synaptic Package Manager" src="http://jimmod.com/blog/wp-content/uploads/2010/03/Screenshot-Synaptic-Package-Manager-150x150.png" alt="Screenshot-Synaptic Package Manager" width="150" height="150" /><p class="wp-caption-text">Screenshot-Synaptic Package Manager</p></div>
<ul>
<li><span style="font-size: small;">Right click on the pidgin and select <em>mark for upgrade</em> and click <em>apply</em></span></li>
</ul>
<p><span style="font-size: small;">I hope the explanation is clear enough <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p style="text-align: left;"><span style="font-size: small;">Cheers..</span></p>
<p><span style="font-size: small; "><em><br />
</em></span></p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2009/06/solving-pidgin-cannot-connect-ym/' rel='bookmark' title='Permanent Link: Solving Pidgin cannot connect to Yahoo Messenger (YM)'>Solving Pidgin cannot connect to Yahoo Messenger (YM)</a></li><li><a href='http://jimmod.com/blog/2010/06/solving-fixing-ubuntu-10-04-lucid-screen-flickerdistortion/' rel='bookmark' title='Permanent Link: Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion'>Solving (fixing) ubuntu 10.04 (lucid) screen flicker/distortion</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2010/03/updating-pidgin-to-latest-version-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java ME (J2ME) JSON Implementation Tutorial/Sample</title>
		<link>http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/</link>
		<comments>http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 05:48:25 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[java me]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jimmod.com/blog/?p=126</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		JSON is one of the most popular format used for communicating between (Java ME) J2ME client and App Server. Strangely it&#8217;s hard to find JSON implementation sample in J2ME. So I decide to write a sample.

&#8211; Next Tutorial : Java ME (J2ME) JSON Implementation For Array Object &#8211;
The JSON library I used [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation For Array Object'>Java ME (J2ME) JSON Implementation For Array Object</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2010%2F03%2Fjava-me-j2me-json-implementation-tutorialsample%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Java ME (J2ME) JSON Implementation Tutorial/Sample" data-url="http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>JSON is one of the most popular format used for communicating between (Java ME) J2ME client and App Server. Strangely it&#8217;s hard to find JSON implementation sample in J2ME. So I decide to write a sample.</p>
<p><span id="more-126"></span></p>
<p>&#8211; <a href="http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/" target="_blank">Next Tutorial : Java ME (J2ME) JSON Implementation For Array Object</a> &#8211;</p>
<p>The JSON library I used is from json.org :<a href="http://www.json.org/java/org.json.me.zip"> http://www.json.org/java/org.json.me.zip</a><br />
(link reported not valid anymore, try the one I&#8217;ve uploaded : <a href="http://www.megaupload.com/?d=QDW9N225">http://www.megaupload.com/?d=QDW9N225</a>)</p>
<p>Extract it to your source code folder.</p>
<p>For example we have this User Class:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> description<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To implement JSON to this class I usually create an Interface JSONAble:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> JSONAble <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> toJSON<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">void</span> fromJSON<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To make the User class is JSON compatible <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  let&#8217;s add the JSONAble interface &amp; implement it:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #000000; font-weight: bold;">implements</span> JSONAble<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> description<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> description<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDescription<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> description<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">description</span> <span style="color: #339933;">=</span> description<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">+</span>getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">+</span>getDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> fromJSON<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> jsonString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			JSONObject json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setId<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setName<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			setDescription<span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toJSON<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		JSONObject inner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span>, getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>, getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			inner.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span>, getDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> inner.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To test it let&#8217;s create a MIDlet that have these startApp() implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Converting Object to JSON</span>
		User user <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		user.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		user.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jimmy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		user.<span style="color: #006633;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testing json in j2me&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Convert to JSON : &quot;</span><span style="color: #339933;">+</span>user.<span style="color: #006633;">toJSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Converting JSON to Object</span>
		<span style="color: #003399;">String</span> sample <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>id<span style="color: #000099; font-weight: bold;">\&quot;</span>:99,<span style="color: #000099; font-weight: bold;">\&quot;</span>name<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>tester<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>description<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>This is JSON Data<span style="color: #000099; font-weight: bold;">\&quot;</span>}&quot;</span><span style="color: #339933;">;</span>
		User user2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		user2.<span style="color: #006633;">fromJSON</span><span style="color: #009900;">&#40;</span>sample<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Convert from JSON : &quot;</span><span style="color: #339933;">+</span>user2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see the output results:<br />
<code>Convert to JSON : {"name":"jimmy","description":"testing json in j2me","id":10}<br />
Convert from JSON : 99-tester-This is JSON Data</code></p>
<p>The toJSON() function is the implementation how the object converted to JSON format. In J2ME we still implement it manually since we don&#8217;t have Java reflection which can enable automatically scan the variables.<br />
What the JSON library help is building the JSON data. We just need to put the variables.</p>
<p>On the fromJSON() function what it does is getting out the data from JSON format and set it to class variables.</p>
<p>Next I will cover about converting more complex class structure.<br />
Or create a fromJSON () &amp; toJSON() generator (:?). Let see..</p>
<p>Thanks for reading this, although this is the basic hope it&#8217;ll help <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8211; <a href="../2011/09/java-me-j2me-json-implementation-for-array-object/" target="_blank">Next Tutorial : Java ME (J2ME) JSON Implementation For Array Object</a> &#8211;</p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation For Array Object'>Java ME (J2ME) JSON Implementation For Array Object</a></li><li><a href='http://jimmod.com/blog/2010/04/basic-lwuit-tutorial-with-eclipse-pulsar/' rel='bookmark' title='Permanent Link: Basic LWUIT tutorial/sample with Eclipse Pulsar'>Basic LWUIT tutorial/sample with Eclipse Pulsar</a></li><li><a href='http://jimmod.com/blog/2011/02/jimmys-blog-send-receiving-on-specific-port-with-j2me-application/' rel='bookmark' title='Permanent Link: Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application'>Jimmy&#8217;s Blog &#8211; Send &#038; Receiving SMS on specific Port with J2ME Application</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>

