<?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>Andi Sunyoto Personal Blog &#187; Add</title>
	<atom:link href="http://www.andisun.com/tag/add/feed" rel="self" type="application/rss+xml" />
	<link>http://www.andisun.com</link>
	<description>andi&#124;blog</description>
	<lastBuildDate>Wed, 28 Dec 2011 12:24:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Menangkap Event pada Tombol</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/menangkap-event-pada-tombol</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/menangkap-event-pada-tombol#comments</comments>
		<pubDate>Wed, 22 Jul 2009 07:54:09 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[Add]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[J2ME]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=217</guid>
		<description><![CDATA[Agar sebuah tombol dapat berfungsi, maka event yang terjadi pada tombol harus di tangkap. Program diatas ketika di klik tombol Exit belum dapat keluar dari program. ?View Code JAVA1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [...]]]></description>
			<content:encoded><![CDATA[<p>Agar sebuah tombol dapat berfungsi, maka event yang terjadi pada tombol harus di tangkap.</p>
<p>Program diatas ketika di klik tombol Exit belum dapat keluar dari program.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p217code2'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2172"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p217code2"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.*</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> EventCommand <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>
    <span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> TextBox mainScreen<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdExit<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> EventCommand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        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>
        mainScreen <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextBox<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello&quot;</span>, <span style="color: #0000ff;">&quot;Hello World&quot;</span>, <span style="color: #cc66cc;">512</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        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>
        mainScreen.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mainScreen.<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>
    <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> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>mainScreen<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> 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: #000000; font-weight: bold;">public</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: #009900;">&#123;</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>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            destroyApp<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Hal-hal yang harus disertakan dalam menangkap sebuah event adalah:</p>
<ol>
<li>&#8230; implement Command Listener</li>
<li>&#8230; setComamndListener</li>
<li>&#8230; commandAction</li>
</ol>
<p><strong>Catatan:</strong></p>
<p>Ketika menambahkan implement CommandListener maka akan terdapat pesan kesalahan. Kesalahan tersebut terjadi karena jika menggunakan interface Command Listener harus disertai dengan method commandAction.</p>
<p>Aksi yang akan terjadi pada event di atur pada method commandAction. Pada aplikasi ini ketika ditekan tombol &#8220;Exit&#8221;, maka akan keluar dari program.</p>
<pre>public void commandAction(Command c, Displayable d) {
 if (c==cmdExit){
  destroyApp(false);
  notifyDestroyed();
 }
}</pre>
<p>Hasil running program di atas adalah:</p>
<div id="attachment_223" class="wp-caption alignleft" style="width: 252px"><img class="size-full wp-image-223  " title="j2me_event01" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_event01.png" alt="Sebelum di klik &quot;Exit&quot;" width="242" height="358" /><p class="wp-caption-text">Sebelum diklik &quot;Exit&quot;</p></div>
<div id="attachment_224" class="wp-caption alignleft" style="width: 259px"><img class="size-full wp-image-224  " title="j2me_event02" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_event02.png" alt="Setelah diklik &quot;Exit&quot;" width="249" height="358" /><p class="wp-caption-text">Setelah diklik &quot;Exit&quot;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/menangkap-event-pada-tombol/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Menambah Tombol</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/menambah-tombol</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/menambah-tombol#comments</comments>
		<pubDate>Wed, 22 Jul 2009 03:35:56 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[Add]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[Remove]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=206</guid>
		<description><![CDATA[Tombol pada sebuah aplikasi sangat penting. Tombol biasanya digunakan untuk mengendalikan jalannya program. Pada program ini kita akan menambahkan tombol pada aplikasi J2ME. ?View Code JAVA1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Tombol pada sebuah aplikasi sangat penting. Tombol biasanya digunakan untuk mengendalikan jalannya program. Pada program ini kita akan menambahkan tombol pada aplikasi J2ME.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p206code4'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2064"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p206code4"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.*</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> AddCommand <span style="color: #000000; font-weight: bold;">extends</span> MIDlet<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> TextBox mainScreen<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdExit<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AddCommand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        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>
        mainScreen <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextBox<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello&quot;</span>, <span style="color: #0000ff;">&quot;Hello World&quot;</span>, <span style="color: #cc66cc;">512</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        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>
        mainScreen.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<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> startApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>mainScreen<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> 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: #000000; font-weight: bold;">public</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: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Mendefinisikan tombol pada J2ME menggunakan class <strong>Command.</strong> Berikut mendefinisikan tombol bernama cmdExit:</p>
<pre>public class AddCommand extends MIDlet {
   ...
   private Command cmdExit;</pre>
<p>Membuat bentuk instant cmdExit dan menambahkannya kedalam Class mainScreen. Class main screen harus turunan dari class Displayable.</p>
<pre>public AddCommand(){
...
cmdExit = new Command("Exit", Command.EXIT, 1);
mainScreen.addCommand(cmdExit);
}</pre>
<p>Tampilan program di atas adalah sebagai berikut</p>
<div id="attachment_214" class="wp-caption alignnone" style="width: 257px"><img class="size-full wp-image-214" title="j2me_addcommand" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_addcommand1.png" alt="Tombol Exit Muncul pada Bagian Kiri" width="247" height="364" /><p class="wp-caption-text">Tombol Exit Muncul pada Bagian Kiri</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/menambah-tombol/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

