<?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> &#187; canvas</title>
	<atom:link href="http://www.andisun.com/tag/canvas/feed" rel="self" type="application/rss+xml" />
	<link>http://www.andisun.com</link>
	<description></description>
	<lastBuildDate>Tue, 30 Mar 2010 02:20:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 sesuai dengan keinginan [...]]]></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>
	</channel>
</rss>
