<?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; Tutorials</title>
	<atom:link href="http://www.andisun.com/category/tutorials/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>J2ME: Menampilkan Gambar dengan Class Canvas</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/j2me-menampilkan-gambar</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/j2me-menampilkan-gambar#comments</comments>
		<pubDate>Fri, 15 Jan 2010 02:52:08 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[J2ME]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=551</guid>
		<description><![CDATA[Salah satu kelebihan class Canvas adalah dapat menampilkan gambar. Pada modul ini kita akan membahas kode program untuk menampilkan file gambar di layar handphone. Pertama anda siapkan file gambar yang akan ditampilkna. Biasanya file gambar yang ditampilkan dalam layar HP bertipe “PNG”. Siapkan gambar degan nama dan extensi berikut: &#8220;btw.png,globe.png,ipod.png,printer.png,sepeda.png&#8221; File di atas dapat diganti [...]]]></description>
			<content:encoded><![CDATA[<p>Salah satu kelebihan class Canvas adalah dapat menampilkan gambar. Pada modul ini kita akan membahas kode program untuk menampilkan file gambar di layar handphone.</p>
<p>Pertama anda siapkan file gambar yang akan ditampilkna. Biasanya file gambar yang ditampilkan dalam layar HP bertipe “PNG”.</p>
<p>Siapkan gambar degan nama dan extensi berikut: &#8220;btw.png,globe.png,ipod.png,printer.png,sepeda.png&#8221;<br />
File di atas dapat diganti sesuai dengan keinginan kita.</p>
<p><strong>MIDShowImage.java</strong></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('p551code2'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5512"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code" id="p551code2"><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>
&nbsp;
<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> ShowImageNext <span style="color: #000000; font-weight: bold;">extends</span> MIDlet <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acanvas+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Canvas</span></a> canvas<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> Command cmdNExt<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> ShowImageNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
canvas <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CanvasShowImg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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>
&nbsp;
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: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>canvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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>
&nbsp;
<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>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//End of MIDlet</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CanvasShowImg <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acanvas+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Canvas</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a> currentImg<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> CanvasShowImg<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> paint<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Graphics</span></a> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//set background to white</span>
&nbsp;
g.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>0xFFFFFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
g.<span style="color: #006633;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getWidth</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: #006633;">getHeight</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;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> option <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;/btw.png&quot;</span>, <span style="color: #0000ff;">&quot;/globe.png&quot;</span>, <span style="color: #0000ff;">&quot;/ipod.png&quot;</span>, <span style="color: #0000ff;">&quot;/printer.png&quot;</span>, <span style="color: #0000ff;">&quot;/sepeda.png&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
currentImg <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span>option<span style="color: #009900;">&#91;</span>counter<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>counter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
g.<span style="color: #006633;">drawImage</span><span style="color: #009900;">&#40;</span>currentImg, getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Graphics</span></a>.<span style="color: #006633;">VCENTER</span> <span style="color: #339933;">|</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Graphics</span></a>.<span style="color: #006633;">HCENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> keycode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>getGameAction<span style="color: #009900;">&#40;</span>keycode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acanvas+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Canvas</span></a>.<span style="color: #006633;">RIGHT</span><span style="color: #339933;">:</span>
&nbsp;
counter <span style="color: #339933;">=</span> counter <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
repaint<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;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acanvas+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Canvas</span></a>.<span style="color: #006633;">LEFT</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Hasil program di atas adalah sebagai berikut:</p>
<div id="attachment_554" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.andisun.com/wp-content/uploads/2010/01/tampil_gambar1.png"><img class="size-full wp-image-554" title="tampil_gambar" src="http://www.andisun.com/wp-content/uploads/2010/01/tampil_gambar1.png" alt="Program menampilkan gambar" width="300" height="383" /></a><p class="wp-caption-text">Program menampilkan gambar</p></div>
<p><strong>Keterangan:</strong></p>
<p>Klik panah ke kanan untuk melihat gambar selanjutnya.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/j2me-menampilkan-gambar/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro JavaScript and Hello World</title>
		<link>http://www.andisun.com/tutorials/javascript-tutorials/intro-javascript-and-hello-world</link>
		<comments>http://www.andisun.com/tutorials/javascript-tutorials/intro-javascript-and-hello-world#comments</comments>
		<pubDate>Sun, 13 Sep 2009 02:17:40 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Hello World]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=453</guid>
		<description><![CDATA[JavaScript adalah bahasa scripting yang popular di internet dan dapat bekerja di sebagian besar browser popular seperti Internet Explorer (IE), Mozilla FireFox, Netscape dan Opera. Kode JavaScript dapat disisipkan dalam halaman web menggunakan tag SCRIPT.]]></description>
			<content:encoded><![CDATA[<p>JavaScript adalah bahasa <em>scripting</em> yang popular di internet dan dapat bekerja di sebagian besar browser popular seperti Internet Explorer (IE), Mozilla FireFox, Netscape dan Opera. Kode JavaScript dapat disisipkan dalam halaman web menggunakan tag SCRIPT.</p>
<p>Beberapa hal tentang JavaScript:</p>
<ol>
<li>JavaScript didesain untuk menambah interaktif suatu web.</li>
<li>JavaScript merupakan sebuah bahasa <em>scripting.</em></li>
<li>Bahasa <em>scripting</em> merupakan bahasa pemrograman yang ringan.</li>
<li>JavaScript berisi baris kode yang dijalankan di komputer (web browser).</li>
<li>JavaScript biasanya disisipkan <em>(</em><em>embedded</em><em>)</em> dalam halaman HTML.</li>
<li>JavaScript adalah bahasa interpreter (yang berarti skrip dieksekusi tanpa proses kompilasi).</li>
<li>Setiap orang dapat menggunakan JavaScript tanpa membayar lisensi.</li>
</ol>
<p>Contoh skrip JavaScript dapat dilihat pada contoh berikut:</p>
<p><strong>Nama file: js01.html</strong></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('p453code3'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4533"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p453code3"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;JavaScript&lt;/title&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    document.write(&quot;Hello world!&quot;);
    document.write(&quot;&lt;p&gt;Apa Kabar &lt;br /&gt;&quot; +
                   &quot;&lt;i&gt;anda&lt;/i&gt;?&lt;/p&gt;&quot;);
  &lt;/script&gt;
&nbsp;
  &lt;p&gt;Demo output untuk menampilkan teks.
  &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p><strong>Output file: js01.html</strong></p>
<div id="attachment_461" class="wp-caption aligncenter" style="width: 385px"><a href="http://www.andisun.com/wp-content/uploads/2009/09/JavaScript_hello_world.png"><img class="size-full wp-image-461" title="JavaScript_hello_world" src="http://www.andisun.com/wp-content/uploads/2009/09/JavaScript_hello_world.png" alt="Menampilkan skrip pada HTML" width="375" height="256" /></a><p class="wp-caption-text">Menampilkan skrip pada HTML</p></div>
<p>Keterangan:</p>
<ul>
<li>document.write : untuk menampilkan teks di halaman HTML.</li>
</ul>
<p>Teks yang akan ditampilkan dapat dimasukkan ke dalam tag HTML. Tag akan dieksekusi oleh browser ketika teks ditampilkan. Hal mendasar yang perlu diperhatikan dalam JavaScript adalah:</p>
<ul>
<li>Seperti pada C++/Java, perintah dalam Java diakhiri dengan ”;” (titik koma).</li>
<li>Komentar menggunakan:</li>
</ul>
<p style="padding-left: 30px;">//           : untuk satu baris perintah</p>
<p style="padding-left: 30px;">/*&#8230;*/  : untuk kelompok program (banyak baris)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/javascript-tutorials/intro-javascript-and-hello-world/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>J2ME: Form dan Ticker</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/j2me-form-dan-ticker</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/j2me-form-dan-ticker#comments</comments>
		<pubDate>Fri, 11 Sep 2009 02:07:24 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[MIDlet]]></category>
		<category><![CDATA[ticker]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=442</guid>
		<description><![CDATA[Apabila sedang menyaksikan tayangan pada televisi akan sering terlihat berita pada bagian bawah layar yang berupa tulisan berjalan. Atau pada acara yang berhubungan dengan bursa efek akan bisa dilihat juga berupa tulisan berjalan yang memberikan informasi mengenai keadaan saham pada saat itu. Untuk membuat “tayangan” seperti itu pada layar ponsel dapat digunakan class Ticker. Class [...]]]></description>
			<content:encoded><![CDATA[<p>Apabila sedang menyaksikan tayangan pada televisi akan sering terlihat berita pada bagian bawah layar yang berupa tulisan berjalan. Atau pada acara yang berhubungan dengan bursa efek akan bisa dilihat juga berupa tulisan berjalan yang memberikan informasi mengenai keadaan saham pada saat itu. Untuk membuat “tayangan” seperti itu pada layar ponsel dapat digunakan class Ticker.</p>
<p>Class Ticker tampak seperti animasi teks berjalan terus menerus dari kanan ke  kiri. Untuk menampilkan obyek Ticker yang telah dibuat, kita perlu memanggil method setTicker() yang didefinisikan pada class Displayable. Ini artinya, method tersebut dapat kita panggil dari obyek turunan dari kelas Screen maupun Canvas.</p>
<p>Pada modul ini akan mengekplorasi ticker. Disini akan membuat obyek Ticker dan mengkaitkannya dengan obyek Form.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p442code6'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4426"><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
34
35
36
</pre></td><td class="code" id="p442code6"><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> MIDTicker <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> Form form<span style="color: #339933;">;</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> Ticker ticker<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdKeluar<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> MIDTicker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		cmdKeluar <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;Keluar&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>
		ticker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ticker<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Saham TELKOM naik 10 point&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form <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;Ticker&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">setTicker</span><span style="color: #009900;">&#40;</span>ticker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdKeluar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<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: #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>
		display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>form<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> cmdKeluar<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>Berikut keterangan kode program di atas:</p>
<p>Untuk membuat objek ticker digunakan baris berikut :</p>
<pre>ticker = new Ticker("Ini text berjalan yang akan ditampilan pada layar ");</pre>
<p>Sedangkan untuk menambahkan objek ticker pada form digunakan method setTicker(objekTicker), seperti di bawah ini :</p>
<pre>form.setTicker(ticker);</pre>
<p>Berbeda pada ponsel lainnya, pada Siemens, teks dari objek ticker menempati baris sama dengan title dari form. Selain itu, teks pada objek ticker hanya berjalan setelah layar saja.</p>
<p><a href="http://www.andisun.com/wp-content/uploads/2009/09/midlet_ticker01.png"><img class="aligncenter size-full wp-image-443" title="midlet_ticker01" src="http://www.andisun.com/wp-content/uploads/2009/09/midlet_ticker01.png" alt="midlet_ticker01" width="239" height="308" /></a></p>
<h2>1.1.    Setting Teks pada Ticker</h2>
<p>Pada class Ticker terdapat dua method yaitu getString() dan setString(String str). Berikut adalah contoh untuk aplikasi yang memberikan fasilitas bagi user untuk mengubah teks yang ditampilkan oleh objek ticker. Berikut adalah contoh dari aplikasi tersebut. Aplikasi ini dapat memodifikasi aplikasi ticker sebelumnya.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p442code7'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4427"><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
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p442code7"><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> MIDTickerLanjut <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> Form form<span style="color: #339933;">;</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> Ticker ticker<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdKeluar<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Command cmdTicker<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextfield+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextField</span></a> textField<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> MIDTickerLanjut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		cmdKeluar <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;Keluar&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>
		cmdTicker <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;Set Ticker&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		textField <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextfield+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextField</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teks : &quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span>, <span style="color: #cc66cc;">50</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextfield+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextField</span></a>.<span style="color: #006633;">ANY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ticker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ticker<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form <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;Ticker&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>textField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdKeluar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdTicker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<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: #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>
		display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>form<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> cmdKeluar<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">==</span> cmdTicker<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			form.<span style="color: #006633;">setTicker</span><span style="color: #009900;">&#40;</span>ticker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ticker.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span>textField.<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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Aplikasi ini merupakan hasil modifikasi dari MIDTickerLanjut.java. Objek yang ditambahkan adalah objek textField yang akan digunakan oleh user untuk memasukkan teks yang akan digunakan oleh objek ticker. Pada konstruktor hanya dilakukan pembuatan objek ticker dan belum ditambahkan pada objek form. Setelah “tombol” Ticker ditekan baru objek ticker ditambahkan pada form dengan baris seperti berikut ini:</p>
<pre>if (c == cmdTicker) {
  form.setTicker(ticker);
  ticker.setString(textField.getString());
}</pre>
<p>Untuk menampilkan teks yang diisikan user pada textField digunakan baris berikut:</p>
<pre>ticker.setString(textField.getString());</pre>
<p><a href="http://www.andisun.com/wp-content/uploads/2009/09/midlet_ticker02.png"><img class="aligncenter size-full wp-image-444" title="midlet_ticker02" src="http://www.andisun.com/wp-content/uploads/2009/09/midlet_ticker02.png" alt="midlet_ticker02" width="487" height="314" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/j2me-form-dan-ticker/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>J2ME: Memanfaatkan Class TextBox</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/j2me-memanfaatkan-class-textbox</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/j2me-memanfaatkan-class-textbox#comments</comments>
		<pubDate>Wed, 29 Jul 2009 00:21:15 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[TextBox]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=312</guid>
		<description><![CDATA[Class TextBox merupakan turunan dari class Screen yang merepresentasikan sebuah kotak untuk mengisi teks. Konstruktor class TextBox adalah sebagai berikut: TextBox(String title, String text, int maxSize, int constraints); Agar lebih jelas untuk memahami tentang class TextBox berikut contoh programnya: ?View Code JAVA1 2 3 4 5 6 7 8 9 10 11 12 13 14 [...]]]></description>
			<content:encoded><![CDATA[<p>Class <span style="font-family: courier new,courier;">TextBox</span> merupakan turunan dari class <span style="font-family: courier new,courier;">Screen </span>yang merepresentasikan sebuah kotak untuk mengisi teks.</p>
<p>Konstruktor class TextBox adalah sebagai berikut:</p>
<p style="padding-left: 30px;"><span style="font-family: terminal,monaco;">TextBox(String title, String text, int maxSize, int constraints);</span></p>
<p>Agar lebih jelas untuk memahami tentang class <span style="font-family: courier new,courier;">TextBox </span>berikut contoh programnya:</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('p312code9'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3129"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code" id="p312code9"><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> MIDTextBox <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> Display display<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> TextBox txt<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Form form<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Alert alert<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;">private</span> Command cmdSetText<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdInsertText<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdClearText<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdInfoText<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdBack<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MIDTextBox<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>
        txt <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;Contoh Midlet TextBox&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #cc66cc;">256</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextfield+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextField</span></a>.<span style="color: #006633;">ANY</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>
        cmdSetText <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;Set Text&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdInsertText <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;Insert&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdInfoText <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;Info Text&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdBack <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;Back&quot;</span>, Command.<span style="color: #006633;">BACK</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        txt.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        txt.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdSetText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        txt.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdInsertText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        txt.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdInfoText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        txt.<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>txt<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;">true</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: #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> cmdSetText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            txt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contoh Mengeset Text dalam TextBox&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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">==</span> cmdInsertText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            txt.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Text Sisipan&quot;</span>, <span style="color: #cc66cc;">0</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> cmdClearText<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>txt.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                txt.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, txt.<span style="color: #006633;">size</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: #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> cmdInfoText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            form <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;Informasi Text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            form.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teks Aktif: &quot;</span> <span style="color: #339933;">+</span> txt.<span style="color: #006633;">getString</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>
            form.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Jumlah Karakter: &quot;</span> <span style="color: #339933;">+</span> txt.<span style="color: #006633;">size</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>
            form.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Posisi cursor: &quot;</span> <span style="color: #339933;">+</span> txt.<span style="color: #006633;">getCaretPosition</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;
            form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdBack<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            form.<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>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>form<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> cmdBack<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>txt<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>Hasil program di atas adalah sebagai berikut:</p>
<p><span id="more-312"></span></p>
<div id="attachment_343" class="wp-caption alignnone" style="width: 223px"><img class="size-full wp-image-343" title="j2me_textbox_01" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_textbox_011.png" alt="Tampilan Awal" width="213" height="314" /><p class="wp-caption-text">Tampilan Awal</p></div>
<p>Setelah muncul gambar di atas, dapat dicoba diklik &#8220;Menu&#8221;, hasilnya adalah:</p>
<div id="attachment_344" class="wp-caption alignnone" style="width: 224px"><img class="size-full wp-image-344" title="j2me_textbox_02" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_textbox_02.png" alt="Pilihan Menu Aplikasi" width="214" height="314" /><p class="wp-caption-text">Pilihan Menu Aplikasi</p></div>
<p>Coba pilih menu Info Text, hasilnya adalah:</p>
<div id="attachment_345" class="wp-caption alignnone" style="width: 225px"><img class="size-full wp-image-345" title="j2me_textbox_03" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_textbox_03.png" alt="Tampilan menu &quot;Info Text&quot;" width="215" height="314" /><p class="wp-caption-text">Tampilan menu &quot;Info Text&quot;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/j2me-memanfaatkan-class-textbox/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Memanfaatkan Class List</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/memanfaatkan-class-list</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/memanfaatkan-class-list#comments</comments>
		<pubDate>Thu, 23 Jul 2009 15:30:42 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[exclusive]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[implicit]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[multiple]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=265</guid>
		<description><![CDATA[Class List merupakan turunan dari class Screen. Class ini berfungsi untuk menampilkan daftar item pilihan yang dapat diakses denagn cara menscroll. Untuk memilih item yang diinginkan dengan menekan tombol select atau menggunakan Command. Bentuk constructor List adalah sebagai berikut: List(String title, int listType) List(String title, int listType, String[] choices, Image[] images) Daftar method clas List [...]]]></description>
			<content:encoded><![CDATA[<p>Class <span style="font-family: courier new,courier;">List</span> merupakan turunan dari class <span style="font-family: courier new,courier;">Screen</span>. Class ini berfungsi untuk menampilkan daftar item pilihan yang dapat diakses denagn cara menscroll. Untuk memilih item yang diinginkan dengan menekan tombol select atau menggunakan <span style="font-family: courier new,courier;">Command</span>.</p>
<p>Bentuk constructor List adalah sebagai berikut:</p>
<ul>
<li><span style="font-family: terminal,monaco;">List(String title, int listType)</span></li>
<li><span style="font-family: terminal,monaco;">List(String title, int listType, String[] choices, Image[] images)</span></li>
</ul>
<p>Daftar method clas <span style="font-family: courier new,courier;">List </span>yang digunakan untuk memanipulasi item adalah:</p>
<table style="width: 591px; height: 134px;" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td width="127">
<p align="center"><strong>Nama Method</strong></p>
</td>
<td width="454">
<p align="center"><strong>Kegunaan</strong></p>
</td>
</tr>
<tr>
<td width="127"><span style="font-family: courier new,courier;">append()</span></td>
<td width="454"><span style="font-family: arial,helvetica,sans-serif;">Menambah item   dan menempatkannya pada posisi terakhir.</span></td>
</tr>
<tr>
<td width="127"><span style="font-family: courier new,courier;">insert()</span></td>
<td width="454"><span style="font-family: arial,helvetica,sans-serif;">Menambah item   dan menempatkannya di posisi sebelum item yang aktif(item yang sedang   dipilih)</span></td>
</tr>
<tr>
<td width="127"><span style="font-family: courier new,courier;">delete()</span></td>
<td width="454"><span style="font-family: arial,helvetica,sans-serif;">Menghapus item   yang sedang dipilih.</span></td>
</tr>
<tr>
<td width="127"><span style="font-family: courier new,courier;">deleteAll()</span></td>
<td width="454"><span style="font-family: arial,helvetica,sans-serif;">Menghapus   semua item yan gterdapat pada objek List.</span></td>
</tr>
</tbody>
</table>
<p>Parameter choices digunakan untuk melewatkan item-item yang diisikan, sedangkan images digunakan untuk menyimpan daftar gambar (icon) yang akan ditampilkan.</p>
<p>Dalam class List ada tiga macam tipe:</p>
<table style="width: 598px; height: 137px;" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td width="102"><strong>Tipe</strong></td>
<td width="479"><strong>Keterangan</strong></td>
</tr>
<tr>
<td width="102"><span style="font-family: courier new,courier;">EXCLUSIVE</span></td>
<td width="479"><span style="font-family: arial,helvetica,sans-serif;">List ini berbentuk radio button. User hanya dapat memilih   satu pilihan.</span></td>
</tr>
<tr>
<td width="102"><span style="font-family: courier new,courier;">MULTIPLE</span></td>
<td width="479"><span style="font-family: arial,helvetica,sans-serif;">List berupa   list yang didalamnya dilengkapi dengan ChecBox. User dapat memilih lebih dari satu pilihan.</span></td>
</tr>
<tr>
<td width="102"><span style="font-family: courier new,courier;">IMPLICITE</span></td>
<td width="479"><span style="font-family: arial,helvetica,sans-serif;">List standar   yang biasa digunakan untuk menampilkan item pilihan.</span></td>
</tr>
</tbody>
</table>
<p>Untuk mengetahui gambar-gambar mana yang dipilih, class List mendefinisikan method-method sebagai berikut:</p>
<pre>public int getSelectedIndex()
public void getSelectedFlags(boolean[] selected)
public boolean isSelected(int elemenNum)</pre>
<p>Sebelum memulai menuliskan program kita siapkan dulu icon yang akan dimunculkan pada List. Format gambar yang digunakan untuk icon adalah PNG. Berikut icon yang yang akan digunakan:</p>
<table style="width: 179px; height: 149px;" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td><strong>Nama File</strong></td>
<td><strong>Images</strong></td>
</tr>
<tr>
<td>register.png</td>
<td><img class="aligncenter size-full wp-image-266" title="register" src="http://www.andisun.com/wp-content/uploads/2009/07/register.png" alt="register" width="20" height="22" /></td>
</tr>
<tr>
<td>tools.png</td>
<td><img class="aligncenter size-full wp-image-267" title="tools" src="http://www.andisun.com/wp-content/uploads/2009/07/tools.png" alt="tools" width="20" height="20" /></td>
</tr>
<tr>
<td>wizard.png</td>
<td><img class="aligncenter size-full wp-image-268" title="wizard" src="http://www.andisun.com/wp-content/uploads/2009/07/wizard.png" alt="wizard" width="20" height="20" /></td>
</tr>
<tr>
<td>contact.png</td>
<td><img class="aligncenter size-full wp-image-269" title="contact" src="http://www.andisun.com/wp-content/uploads/2009/07/contact.png" alt="contact" width="20" height="20" /></td>
</tr>
<tr>
<td>help.png</td>
<td><img class="aligncenter size-full wp-image-270" title="help" src="http://www.andisun.com/wp-content/uploads/2009/07/help.png" alt="help" width="20" height="20" /></td>
</tr>
</tbody>
</table>
<p><span id="more-265"></span></p>
<p>Copykan file di atas jadi satu direktori dengan file Java, yaitu direktory: <span style="font-family: courier new,courier;">src</span>. Jika dilihat pada tampilan explorer adalah sebagai berikut:</p>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_271" class="wp-caption aligncenter" style="width: 476px"><img class="size-full wp-image-271  " title="j2me_list_icon01" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_icon01.png" alt="Tampilan pada file explorer" width="466" height="80" /><p class="wp-caption-text">Tampilan pada file explorer</p></div></td>
</tr>
</tbody>
</table>
<p>Kode program untuk aplikasi ini adalah:</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('p265code11'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26511"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code" id="p265code11"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.*</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> MIDList <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> Display display<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a> list<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdPilih<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdBack<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a> img1, img2, img3, img4, img5<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MIDList<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>
    <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>
        <span style="color: #666666; font-style: italic;">//membuat objek Command</span>
        cmdPilih <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;Pilih&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdBack <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;Back&quot;</span>, Command.<span style="color: #006633;">BACK</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//membuat daftar icon</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            img1 <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/register.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            img2 <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/contact.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            img3 <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/tools.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            img4 <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/wizard.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            img5 <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/help.png&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;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</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>
&nbsp;
        <span style="color: #666666; font-style: italic;">//membuat List bertipe Exclusive</span>
        list <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;List Tipe Exclusive&quot;</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Achoice+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Choice</span></a>.<span style="color: #006633;">EXCLUSIVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Register&quot;</span>, img1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contact&quot;</span>, img2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Tool&quot;</span>, img3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wizard&quot;</span>, img4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Help&quot;</span>, img5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdPilih<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdBack<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        list.<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>
        display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>list<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> cmdBack<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>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> indeks <span style="color: #339933;">=</span> list.<span style="color: #006633;">getSelectedIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Alert info <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Informasi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            info.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Anda memilih : &quot;</span> <span style="color: #339933;">+</span> list.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>indeks<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            info.<span style="color: #006633;">setTimeout</span><span style="color: #009900;">&#40;</span>Alert.<span style="color: #006633;">FOREVER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>info, list<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>Bentuk tipe List dapat dilihat pada gambar-gambar berikut:</p>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_276" class="wp-caption alignnone" style="width: 201px"><img class="size-full wp-image-276 " title="j2me_list_exclusive" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_exclusive.png" alt="Tipe Exclusive" width="191" height="283" /><p class="wp-caption-text">Tipe Exclusive</p></div></td>
<td>
<p><div id="attachment_279" class="wp-caption alignnone" style="width: 204px"><img class="size-full wp-image-279 " title="j2me_list_exclusive02" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_exclusive02.png" alt="Setelah dipilih tombol &quot;Pilih&quot;" width="194" height="283" /><p class="wp-caption-text">Setelah dipilih tombol &quot;Pilih&quot;</p></div></td>
</tr>
</tbody>
</table>
<p>Jika di ubah tipe Listnya hasilnya masing-masing sebagai berikut:</p>
<table style="width: 100%;" border="0">
<tbody>
<tr>
<td>
<div id="attachment_276" class="wp-caption alignleft" style="width: 163px"><img class="size-full wp-image-276  " title="j2me_list_exclusive" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_exclusive.png" alt="Tipe Exclusive" width="153" height="226" /><p class="wp-caption-text">Tipe Exclusive</p></div>
<div id="attachment_277" class="wp-caption alignleft" style="width: 167px"><img class="size-full wp-image-277  " title="j2me_list_implicit" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_implicit.png" alt="Tipe Implicit" width="157" height="226" /><p class="wp-caption-text">Tipe Implicit</p></div>
<p><div id="attachment_278" class="wp-caption alignleft" style="width: 162px"><img class="size-full wp-image-278  " title="j2me_list_multiple" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_list_multiple.png" alt="Tipe Multiple" width="152" height="226" /><p class="wp-caption-text">Tipe Multiple</p></div></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/memanfaatkan-class-list/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User Interface pada J2ME</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/user-interface-pada-j2me</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/user-interface-pada-j2me#comments</comments>
		<pubDate>Thu, 23 Jul 2009 03:43:38 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[J2ME]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=256</guid>
		<description><![CDATA[Satu hal terpenting dalam sebuah aplikasi adalah Graphical User Interface (GUI). GUI dapat dimanfaatkan sebagai media input dalam sebuah aplikasi. Class-class untuk membangun GUI dalam MIDP disimpan dalam lcdui (javax.microedition.lcdui), sehingga agar dapat memanfaatkan class tersebut dengan mengimport paketnya. Struktur GUI dalam MIDP GUI di dalam MIDP dibagi menjadi dua bagian, yaitu: high-level API (yang [...]]]></description>
			<content:encoded><![CDATA[<p>Satu hal terpenting dalam sebuah aplikasi adalah <em>Graphical User Interface (GUI)</em>. GUI dapat dimanfaatkan sebagai media input dalam sebuah aplikasi.</p>
<p><em>Class-class</em> untuk membangun GUI dalam MIDP disimpan dalam lcdui (<span style="font-family: courier new,courier;">javax.microedition.lcdui</span>), sehingga agar dapat memanfaatkan class tersebut dengan mengimport paketnya.</p>
<p><strong>Struktur GUI dalam MIDP</strong></p>
<p>GUI di dalam MIDP dibagi menjadi dua bagian, yaitu: <em>high-level API</em> (yang didasarkan pada penbentukan window) dan <em>low-level API</em> (yang didasarkan pada pembentukan canvas dan pixel). Penggunaan <em>high-level API</em> lebih mudah disbanding mengunakan <em>low-level API</em> untuk membangun sebuah interface pada suatu aplikasi. Namun dengan menggunakan <em>low level API</em> lebih leluasa dalam mendesain sebuah interface.</p>
<p>Model high-level API menyediakan class-class standar yang digunakan untuk membangun UI <em>(User Interface)</em> seperti component <span style="font-family: courier new,courier;">Form, TextBox, List, Alert</span>. Model High-level mengimplementasikan class-class yang diturunkan dari class Screen.</p>
<p>Model Low-level API memberikan akses yang kepada programmer untuk melakukan control terhadap tampilan layer, termasuk pengembaran menggunakan pixel, pembentukan bentuk geometri (segitiga, segiempat,lingkaran,elips, arc, dll). Model ini sering digunakan untuk membuat game. Karena model ini dapat membuat bentuk tek graphic yang lebih spesifik sesaui dengan keinginan. Model ini juga dapat membaca tombol-tombol yang ditekan oleh user.</p>
<p>Dalam paket lcdui yang dimport menggunakan:</p>
<p style="padding-left: 30px;"><span style="font-family: terminal,monaco;">import javax.microedition.lcdui.*;</span></p>
<p>Paket ini terdiri dari interface dan class.</p>
<p>Tabel daftar interface:</p>
<table style="width: 599px; height: 120px;" border="0" cellspacing="1" cellpadding="2">
<tbody>
<tr>
<td width="157"><strong>Interface</strong></td>
<td width="424"><strong>Keterangan</strong></td>
</tr>
<tr>
<td width="157"><span style="font-family: courier new,courier;">Choice</span></td>
<td width="424">Mengimplementasikan sejumah item pilihan yang   didefinisikan.</td>
</tr>
<tr>
<td width="157"><span style="font-family: courier new,courier;">CommandListener</span></td>
<td width="424">Menerima <em>event-event</em> level tinggi.</td>
</tr>
<tr>
<td width="157"><span style="font-family: courier new,courier;">ItemStateListener</span></td>
<td width="424">Menerima <em>event</em> yang mengindikasikan perubahan keadaan dari item yang terdapat pada obyek Form</td>
</tr>
</tbody>
</table>
<p><span id="more-256"></span></p>
<p>Daftar kelas paket lcdui:</p>
<table style="width: 596px; height: 613px;" border="0" cellspacing="1" cellpadding="2">
<tbody>
<tr>
<td width="118"><strong>Class</strong></td>
<td width="464"><strong>Keterangan</strong></td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Alert</span></td>
<td width="464">Menampilkan pesan ke user untuk periode waktu tertentu</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">AlertType</span></td>
<td width="464">Mendefinisikan tipe objek Alert yang akan ditampilkan</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Canvas</span></td>
<td width="464">Class yang digunakan untuk aplikasi yang membutuhkan   event-event rendah seperti game dan untuk mengambar dilayar.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">ChoiceGroup</span></td>
<td width="464">Meyajikan sekumpulan elemen yang dapat dipilih yang   dimasukkan di dalam Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Command</span></td>
<td width="464">Konstruksi yang mebungkus informasi-informasi yang   dilakukan oleh user.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">CustomItem</span></td>
<td width="464">Membuat   elemen user interface baru yang ditempatkan pada sebuah Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">DateField</span></td>
<td width="464">Komponen yang   digunakan untuk menampilkan tanggal dan waktu.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Display</span></td>
<td width="464">Manager   tampilan</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Displayable</span></td>
<td width="464">Objek yang   memiliki kemampuan ditampilkan pada layar.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Font</span></td>
<td width="464">Mengatur   huruf yang akan ditampilkan ke layar.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Gauge</span></td>
<td width="464">Tampilan   grafis yang digunakan untuk memvisualisasikan nilai tertentu yang diletakkan   pada Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Graphics</span></td>
<td width="464">Menyediakan   kemampuan menggambar pada sebuah Canvas.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Image</span></td>
<td width="464">Digunakan   untuk menyimpan data gambar.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">ImageItem</span></td>
<td width="464">Meyediakan   kotrol layout untuk gambar-gambar yang ditempatkan pada sebuah Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Item</span></td>
<td width="464">Kelas dasar   untuk menempatkan komponen-komponen yang dapat ditempatkan pada sebuah Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">List</span></td>
<td width="464">Layar yang   berisi daftar pilihan</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Screen</span></td>
<td width="464">Kelas dasar   semua komponen layar dalam high-level user interface.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">StringItem</span></td>
<td width="464">Item yang   berisi string yang kemudian ditempatkan pada Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">TextBox</span></td>
<td width="464">Layar yang   mengijinkan user memanipulasi teks dan bisa juga dijadikan media input.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">TextField</span></td>
<td width="464">Komponen   untuk memasukkan teks di atas Form.</td>
</tr>
<tr>
<td width="118"><span style="font-family: courier new,courier;">Ticker</span></td>
<td width="464">Bagian teks   yang berjalan terus-menerus di atas layar. Ticker tidak dapat ditempelkan   pada Canvas.</td>
</tr>
</tbody>
</table>
<p><strong>Arsitektur LCDUI</strong></p>
<p>Beriku hierarki class-class yang diambil dari pake lcdui (<span style="font-family: courier new,courier;">javax.microedition.lcdui</span>)</p>
<div id="attachment_257" class="wp-caption alignnone" style="width: 577px"><img class="size-full wp-image-257 " title="j2me_class_lcdui" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_class_lcdui.png" alt="Hierarki Class LCDUI" width="567" height="262" /><p class="wp-caption-text">Hierarki Class LCDUI</p></div>
<p>Dari class-class di atas yang dapat langsung ditampilkan ke layar hanya turunan dari class <span style="font-family: courier new,courier;">Displayable</span>.</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('p256code13'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25613"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code" id="p256code13"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.*</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> MIDAlert <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> Form form<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Alert alert<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;">private</span> Command cmdAlert<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MIDAlert<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>
        <span style="color: #666666; font-style: italic;">//membuat objek Form</span>
        form <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;Demo Alert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//membuat objek Command</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>
        cmdAlert <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;Alert&quot;</span>, Command.<span style="color: #006633;">SCREEN</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//menambahkan objek Command &quot;cmdExit&quot; dan &quot;cmdAlert&quot;</span>
        form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        form.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdAlert<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//menset event</span>
        form.<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>
        <span style="color: #666666; font-style: italic;">//menentukan objek yang ditampilkan di layar</span>
        display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>form<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> cmdAlert<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//memanggil method tampilAlert</span>
            tampilAlert<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>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;">true</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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> tampilAlert<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>
            <span style="color: #666666; font-style: italic;">//membuat objek Alert dan menentukan String yang ditampilkan</span>
            alert <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Informasi&quot;</span>, <span style="color: #0000ff;">&quot;Pesan ini tampil di User&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//menentukan tipe Alert</span>
            alert.<span style="color: #006633;">setType</span><span style="color: #009900;">&#40;</span>AlertType.<span style="color: #006633;">ALARM</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//menentukan lamanya Alert tampil</span>
            alert.<span style="color: #006633;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//menampilkan Alert</span>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>alert<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><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Sebuah aplikasi biasanya ketika menampilkan pesan menggunakan icon atau gambar tertentu, berikut tambahan kode program agar pesan yang ditampilkan di atas dapat menampilkan pesan yang disertai dengan gambar.</p>
<p>Hasil output dari program di atas adalah:</p>
<div id="attachment_258" class="wp-caption alignnone" style="width: 458px"><img class="size-full wp-image-258" title="j2me_ui_01" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_ui_01.png" alt="Sesudah dan sebelum diklik Alert" width="448" height="234" /><p class="wp-caption-text">Sesudah dan sebelum diklik Alert</p></div>
<p>Ubahlah method <span style="font-family: courier new,courier;">tampilAlert()</span> menjadi seperti berikut:</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 2806px; width: 1px; height: 1px;"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:DontVertAlignCellWithSp /> <w:DontBreakConstrainedForcedTables /> <w:DontVertAlignInTxbx /> <w:Word11KerningPairs /> <w:CachedColBalance /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val=" " /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="0" Name="Body Text" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="0" Name="Plain Text" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false"    UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles> </xml><![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	mso-bidi-font-size:12.0pt; 	font-family:"Verdana","sans-serif"; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} p.CodeBody, li.CodeBody, div.CodeBody 	{mso-style-name:"Code Body"; 	mso-style-unhide:no; 	margin-top:0in; 	margin-right:8.5pt; 	margin-bottom:3.0pt; 	margin-left:8.5pt; 	mso-pagination:widow-orphan; 	background:#F3F3F3; 	mso-layout-grid-align:none; 	text-autospace:none; 	border:none; 	mso-border-top-alt:solid windowtext .5pt; 	mso-border-bottom-alt:solid windowtext .5pt; 	padding:0in; 	mso-padding-alt:1.0pt 0in 1.0pt 0in; 	font-size:10.0pt; 	mso-bidi-font-size:9.0pt; 	font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	color:#231F20;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-size:10.0pt; 	mso-ansi-font-size:10.0pt; 	mso-bidi-font-size:10.0pt;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman","serif";} --> <!--[endif]--></p>
<div style="border-style: solid none; border-color: windowtext -moz-use-text-color; border-width: 1pt medium; padding: 1pt 0in; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; margin-left: 8.5pt; margin-right: 8.5pt;">
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">private void tampilAlert() {</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">try {</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">//membuat objek Image</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">Image img = Image.createImage(&#8220;/globe.png&#8221;);</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">//membuat objek Alert dan menentukan String yang ditampilkan</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">alert = new Alert(&#8220;Informasi&#8221;, &#8220;Pesan ini tampil di User&#8221;, img, null);</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">//menentukan tipe Alert</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">alert.setType(AlertType.ALARM);</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">//menentukan lamanya Alert tampil</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">alert.setTimeout(5000);</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">//menampilkan Alert</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">display.setCurrent(alert);</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">} catch(Exception e) {</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">System.out.println(e.getMessage());</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">}</p>
<p class="CodeBody" style="margin: 0in 0in 3pt; background: #f3f3f3 none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">}</p>
</div>
</div>
<pre>private void tampilAlert() {
	try {
		//membuat objek Image
		Image img = Image.createImage("/globe.png");

		//membuat objek Alert dan menentukan String yang ditampilkan
		alert = new Alert("Informasi", "Pesan ini tampil di User", img, null);

		//menentukan tipe Alert
		alert.setType(AlertType.ALARM);

		//menentukan lamanya Alert tampil
		alert.setTimeout(5000);

		//menampilkan Alert
		display.setCurrent(alert);
	} catch(Exception e)  {
		System.out.println(e.getMessage());
	}
}</pre>
<p>Tampilan ketika ditambahkan gambar pada <span style="font-family: courier new,courier;">Alert</span>.</p>
<div id="attachment_259" class="wp-caption alignnone" style="width: 259px"><img class="size-full wp-image-259" title="j2me_alert_icon" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_alert_icon.png" alt="Tampilan Alert setelah ditambah image" width="249" height="271" /><p class="wp-caption-text">Tampilan Alert setelah ditambah image</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/user-interface-pada-j2me/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Mengelola Tombol (Object Command)</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/mengelola-tombol-object-command</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/mengelola-tombol-object-command#comments</comments>
		<pubDate>Thu, 23 Jul 2009 01:53:03 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[Program]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=248</guid>
		<description><![CDATA[Suatu aplikasi yang menggunakan object Command terkadang memerlukan penambahan tombol dan pengurangan tombol pada saat run-time. Jadi sebuah object Command dapat di tambahkan maupun di kurangkan. Mendeklarasikan Obyek Command Bentuk umum membuat object Command adalah: Command(label, commandType, priority) Contoh: cmdExit = new Command(&#8220;Exit&#8221;, Command.EXIT, 0); Berikut macam-macam tipe Command yang dapat dipakai: Berikut daftar tipe [...]]]></description>
			<content:encoded><![CDATA[<p>Suatu aplikasi yang menggunakan object Command terkadang memerlukan penambahan tombol dan pengurangan tombol pada saat<em> run-time</em>. Jadi sebuah object Command dapat di tambahkan maupun di kurangkan.</p>
<p><strong>Mendeklarasikan Obyek Command</strong></p>
<p>Bentuk umum membuat object Command adalah:</p>
<p style="padding-left: 30px;"><span style="font-family: terminal,monaco;">Command(label, commandType, priority) </span></p>
<p>Contoh:<br />
<span style="font-family: courier new,courier;"> </span></p>
<p style="padding-left: 30px;"><span style="font-family: courier new,courier;">cmdExit = new Command(&#8220;Exit&#8221;, Command.EXIT, 0);</span></p>
<p>Berikut macam-macam tipe Command yang dapat dipakai:</p>
<p>Berikut daftar tipe Command yang dapat digunakan:</p>
<table border="0" cellspacing="1" cellpadding="2">
<tbody>
<tr>
<td width="77">
<p align="center"><span style="font-family: arial,helvetica,sans-serif;"><strong>Tipe</strong></span></p>
</td>
<td width="58">
<p align="center"><span style="font-family: arial,helvetica,sans-serif;"><strong>Nilai</strong></span></p>
</td>
<td width="446">
<p align="center"><span style="font-family: arial,helvetica,sans-serif;"><strong>Keterangan</strong></span></p>
</td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">SCREEN</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">1</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command yang diaplikasikan untuk layer (screen)   tertentu.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">BACK</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">2</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command   yang digunakan untuk kembali ke layar sebelumnya.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">CANCEL</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">3</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Comamnd   yang digunakan untuk jawaban negatif pada dialog box.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">OK</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">4</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command untuk jawaban positif pada dialoag box.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">HELP</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">5</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command   yang digunakan untuk menampilkan help.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">STOP</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">6</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command yang akan menghentikan proses-proses yang   sedang berjalan.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">EXIT</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">7</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command   yang digunakan untuk keluar dari aplikasi.</span></td>
</tr>
<tr>
<td width="77"><span style="font-family: arial,helvetica,sans-serif;">ITEM</span></td>
<td width="58">
<p style="text-align: center;"><span style="font-family: arial,helvetica,sans-serif;">8</span></p>
</td>
<td width="446"><span style="font-family: arial,helvetica,sans-serif;">Tipe Command   yang digunakan untuk menghubungkan aksi dalam suatu Command dengan item di   dalam layar.</span></td>
</tr>
</tbody>
</table>
<p><strong>Menambah Obyek Command</strong></p>
<p>Ada tulisan sebelumnya sudah banyak yang membahas tentang penambahan objek command pada objek lain seperti objek dari class List atau Form. Berikut contoh pengunaan obyek Command.</p>
<p>Untuk menambahkan obyek command menggunakan method  addComamnd().</p>
<p>Contoh:</p>
<p style="padding-left: 30px;"><span style="font-family: courier new,courier;">frm.addCommand(cmdExit);</span></p>
<p><strong>Menghapus Obyek Command</strong></p>
<p>Obyek Command yang telah kita tambahkan di dalam obyek frm dapat dihapus dengan menggunakan method removeCommand().</p>
<p>Contoh:</p>
<p style="padding-left: 30px;"><span style="font-family: courier new,courier;">frm.removeCommand(cmdOpen);</span></p>
<p><strong>Contoh Program</strong></p>
<p><strong><span id="more-248"></span></strong></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('p248code15'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24815"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code" id="p248code15"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.midlet.*</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> MIDCommand <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> Form frm<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;">private</span> Command cmdOpen<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdClose<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdStart<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command cmdStop<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MIDCommand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        frm <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;Contoh Command&quot;</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;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdOpen <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;Open&quot;</span>, Command.<span style="color: #006633;">OK</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdClose <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;Close&quot;</span>, Command.<span style="color: #006633;">OK</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmdStart <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;Start&quot;</span>, Command.<span style="color: #006633;">OK</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//        cmdStop = new Command(label, commandType, priority)</span>
        cmdStop <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;Stop&quot;</span>, Command.<span style="color: #006633;">OK</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        frm.<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>
        frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdExit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdOpen<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>
        display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>frm<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: #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>cmdOpen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            frm.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdOpen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdClose<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>frm<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>cmdStart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            frm.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdClose<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdStop<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>frm<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>cmdStop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            frm.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdStop<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>frm<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>cmdClose<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            frm.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdClose<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">removeCommand</span><span style="color: #009900;">&#40;</span>cmdStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            frm.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>cmdOpen<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><strong>Hasil Runing Program</strong></p>
<div id="attachment_249" class="wp-caption alignleft" style="width: 222px"><img class="size-full wp-image-249" title="j2me_olah_command01" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_olah_command01.png" alt="Sebelum mengklik tombol" width="212" height="314" /><p class="wp-caption-text">Sebelum mengklik tombol</p></div>
<div id="attachment_250" class="wp-caption alignleft" style="width: 221px"><img class="size-full wp-image-250" title="j2me_olah_command02" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_olah_command02.png" alt="Setelah mengklik tombol" width="211" height="314" /><p class="wp-caption-text">Setelah mengklik tombol</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/mengelola-tombol-object-command/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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('p217code17'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21717"><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="p217code17"><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('p206code19'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20619"><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="p206code19"><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>
		<item>
		<title>Hello World</title>
		<link>http://www.andisun.com/tutorials/j2me-programming/181</link>
		<comments>http://www.andisun.com/tutorials/j2me-programming/181#comments</comments>
		<pubDate>Tue, 21 Jul 2009 18:33:10 +0000</pubDate>
		<dc:creator>myandisun</dc:creator>
				<category><![CDATA[J2ME-Mobile Programming]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[world]]></category>

		<guid isPermaLink="false">http://www.andisun.com/?p=181</guid>
		<description><![CDATA[Seperti biasa ketika akan belajar sebuah bahasa pemrograman, program yang pertama kali dibuat adalah "Hello World". Aplikasi ini dapat mengenal MIDlet Life Cycle. Program ini menggunakan J2ME.]]></description>
			<content:encoded><![CDATA[<p>Seperti biasa ketika akan belajar sebuah bahasa pemrograman, program yang pertama kali dibuat adalah &#8220;Hello World&#8221;. Aplikasi ini dapat mengenal MIDlet Life Cycle. Program ini menggunakan <a href="http://www.andisun.com/artikel/sekilas-java-2-microedition-j2me">J2ME</a>.</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('p181code20'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p18120"><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
</pre></td><td class="code" id="p181code20"><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> HelloWorld <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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> HelloWorld<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>
    <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>Ketika program diatas dijalankan menampilkan tulisan “Hello World”. Untuk menutup aplikasi kita harus lewat tombol di window layar emulator.<br />
Hasil pada emulator adalah:</p>
<div id="attachment_220" class="wp-caption alignnone" style="width: 264px"><img class="size-full wp-image-220" title="j2me_hellloworld" src="http://www.andisun.com/wp-content/uploads/2009/07/j2me_hellloworld.png" alt="Tampilan Program Hello World" width="254" height="363" /><p class="wp-caption-text">Tampilan Program Hello World</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andisun.com/tutorials/j2me-programming/181/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

