<?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>Jappit.com &#187; transitions</title>
	<atom:link href="http://www.jappit.com/blog/tag/transitions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jappit.com/blog</link>
	<description>Mobile blog by Alessandro La Rosa</description>
	<lastBuildDate>Wed, 23 Nov 2011 10:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ImageFx: first commercial application is out!</title>
		<link>http://www.jappit.com/blog/2008/10/13/imagefx-first-commercial-application-is-out/</link>
		<comments>http://www.jappit.com/blog/2008/10/13/imagefx-first-commercial-application-is-out/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 11:23:35 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[advertising]]></category>
		<category><![CDATA[cool stuff]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[image library]]></category>
		<category><![CDATA[imagefx]]></category>
		<category><![CDATA[java me]]></category>
		<category><![CDATA[transitions]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=163</guid>
		<description><![CDATA[ImageFx is a Java ME library that allows you to easily add animated transitions between different Images. And today Systema Mutui, the first commercial applications that makes use of it, has finally been launched The application itself is a simple animation that promotes bank services and allows users to share the animation itself with a [...]]]></description>
			<content:encoded><![CDATA[<p><a title="ImageFx launch" href="http://www.jappit.com/blog/2008/06/06/imagefx-j2me-image-effects-library/">ImageFx</a> is a <strong>Java ME library</strong> that allows you to <strong>easily add animated transitions between different Images</strong>.</p>
<p>And today <strong>Systema Mutui</strong>, the <strong>first commercial applications</strong> that makes use of it, has finally <strong>been launched</strong> <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img class="alignnone" title="Systema Mutui screenshot" src="http://www.jappit.com/images/blog/uploads/systema_mutui.jpg" alt="" /></p>
<p>The application itself is a <strong>simple animation</strong> that promotes bank services and allows users to share the animation itself with a friend. Obviously, <a title="ImageFx transitions examples" href="http://www.jappit.com/index.php?page=emulator&amp;midlet=image_fx" target="_blank">ImageFx transitions</a> were used to <strong>make the whole animation nicer</strong> <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To get further details about <strong>ImageFx API features</strong>, you can access its <strong>full JavaDocs</strong> here: <a title="ImageFx JavaDocs" href="http://www.jappit.com/j2me/imagefx/doc/" target="_blank">ImageFx JavaDocs</a>. For any other infos, feel free to <a title="About us page" href="http://www.jappit.com/index.php?page=about_us" target="_blank">contact me</a>!</p>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/10/13/imagefx-first-commercial-application-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add sliding transitions between Canvas in J2ME</title>
		<link>http://www.jappit.com/blog/2008/06/23/how-to-add-sliding-transitions-between-canvas-in-j2me/</link>
		<comments>http://www.jappit.com/blog/2008/06/23/how-to-add-sliding-transitions-between-canvas-in-j2me/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 12:39:03 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[cool stuff]]></category>
		<category><![CDATA[flash lite]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[symbian]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[java me]]></category>
		<category><![CDATA[sliding animations]]></category>
		<category><![CDATA[transitions]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=53</guid>
		<description><![CDATA[Today we&#8217;ll see a simple way to add sliding transition between Canvas in a Java ME application. Just take a look at it in the emulator page to see how it performs: Canvas sliding transitions in action! The source code FxBaseCanvas First of all, we know that Canvas paint() method is protected, so, to access [...]]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;ll see a simple way to add <strong>sliding transition between Canvas</strong> in a Java ME application. Just take a look at it in the emulator page to see how it performs: <a title="Java ME Canvas sliding transition in action" href="http://www.jappit.com/index.php?page=emulator&amp;midlet=canvas_sliding_fx">Canvas sliding transitions in action</a>!</p>
<p><img src="http://www.jappit.com/images/blog/uploads/j2me_canvas_sliding_fx.jpg" alt="j2me canvas sliding transition screenshot" width="247" height="185" /></p>
<h3>The source code</h3>
<h4>FxBaseCanvas</h4>
<p>First of all, we know that <strong>Canvas</strong> <strong>paint()</strong> method is protected, so, to access it from the class we&#8217;ll build, we must extend its visibility by <strong>extending Canvas class itself</strong>. We&#8217;ll do it by defining our <strong>FxBaseClass</strong> in this simple way:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Canvas</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Graphics</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Canvas</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.lcdui.Graphics</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> FxBaseCanvas <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Canvas</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> paint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<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></div></div>

<h4>CanvasSlideFx</h4>
<p>Now, we start building our <strong>CanvasSlideFx </strong>class, that will extend Canvas itself. We start defining some useful properties:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// time related properties</span>
<span style="color: #000066; font-weight: bold;">long</span> startTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">long</span> duration <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// current state of the transition</span>
<span style="color: #000066; font-weight: bold;">boolean</span> running <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// direction of sliding</span>
<span style="color: #000066; font-weight: bold;">int</span> direction <span style="color: #339933;">=</span> LEFT<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// the previous and next Canvas instances</span>
FxBaseCanvas fromCanvas <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
FxBaseCanvas toCanvas <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// the current Display object</span>
Display display <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// properties used to correctly place the 2 Canvas</span>
<span style="color: #000066; font-weight: bold;">int</span> deltaX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> deltaY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, we define our class constructor, that will initialize coordinate properties according to the specified transition direction. The detailed argument list is:</p>
<ul>
<li>The <strong>current Display object</strong>, that will be used to retrieve the current displayed Canvas, and to set the next one</li>
<li><strong>The destination Canvas</strong>, that will extend the previously defined FxBaseCanvas class</li>
<li>The transition <strong>direction</strong> (one of Canvas.UP, RIGHT, DOWN or LEFT)</li>
<li>The transition <strong>duration</strong>, in milliseconds</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> CanvasSlideFx<span style="color: #009900;">&#40;</span>Display display, FxBaseCanvas toCanvas, <span style="color: #000066; font-weight: bold;">int</span> direction, <span style="color: #000066; font-weight: bold;">long</span> duration<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">display</span> <span style="color: #339933;">=</span> display<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fromCanvas</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FxBaseCanvas<span style="color: #009900;">&#41;</span>display.<span style="color: #006633;">getCurrent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">toCanvas</span> <span style="color: #339933;">=</span> toCanvas<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">direction</span> <span style="color: #339933;">=</span> direction<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">duration</span> <span style="color: #339933;">=</span> duration<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>direction<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">case</span> UP<span style="color: #339933;">:</span>
		deltaY <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">case</span> RIGHT<span style="color: #339933;">:</span>
		deltaX <span style="color: #339933;">=</span> getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">case</span> DOWN<span style="color: #339933;">:</span>
		deltaY <span style="color: #339933;">=</span> getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">case</span> LEFT<span style="color: #339933;">:</span>
		deltaX <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, we define a <strong>startTransition()</strong> method, that will actually start the animation. To implement the animation itself, we let our class implement <strong>Runnable</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> startTransition<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;">this</span>.<span style="color: #006633;">startTime</span> <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	running <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And here&#8217;s the <strong>run()</strong> method implementation, that we must implement from Runnable interface. As long as the animation is running, we will repaint our animated Canvas, with a given interval of 50 milliseconds (but you can freely change this). When it finishes (so, running is false), we will exit the main loop and <strong>set the current Displayable</strong> to our <strong>toCanvas</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>running<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			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;">synchronized</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: #009900;">&#123;</span>
				wait<span style="color: #009900;">&#40;</span>50L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	display.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>toCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, we have our <strong>paint()</strong> method, that will actually paint our transition. It will do this by <strong>painting both the source and the destination Canvas</strong>, translating them according to the transition direction, and to the elapsed time.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> paint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<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><span style="color: #339933;">!</span>running<span style="color: #009900;">&#41;</span>
		startTransition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">long</span> diff <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>diff <span style="color: #339933;">&gt;=</span> duration<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		running <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		diff <span style="color: #339933;">=</span> duration<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> perc <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">*</span> diff <span style="color: #339933;">/</span> duration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> dx <span style="color: #339933;">=</span> deltaX <span style="color: #339933;">*</span> perc <span style="color: #339933;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> dy <span style="color: #339933;">=</span> deltaY <span style="color: #339933;">*</span> perc <span style="color: #339933;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
	g.<span style="color: #006633;">translate</span><span style="color: #009900;">&#40;</span>dx, dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fromCanvas.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	g.<span style="color: #006633;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span> deltaX, <span style="color: #339933;">-</span> deltaY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	toCanvas.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	g.<span style="color: #006633;">translate</span><span style="color: #009900;">&#40;</span>deltaX <span style="color: #339933;">-</span> dx, deltaY <span style="color: #339933;">-</span> dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>How to use it?</h3>
<p>Now we&#8217;ll see how to <strong>integrate the CanvasSlideFx within an existing code</strong> that already uses Canvas.<br />
So, let&#8217;s assume that our application currently has, somewhere in its code, these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">MyCanvas firstCanvas <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyCanvas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span>myMidlet<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>firstCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #666666; font-style: italic;">//and somewhere else</span>
MyOtherCanvas secondCanvas <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyOtherCanvas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span>myMidlet<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>secondCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>where MyCanvas and MyOtherCanvas will likely extend Canvas.</p>
<p>Now here are the required steps to integrate transitions in our code:</p>
<ol>
<li> First of all, we must make <strong>MyCanvas and MyOtherCanvas extend FxBaseCanvas </strong>instead of directly Canvas. So, we&#8217;ll have:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyCanvas extend FxBaseCanvas ...</pre></div></div>

</li>
<li> Then, let&#8217;s say we want to animate the transition between firstCanvas and secondCanvas, we will <strong>remove the code</strong>:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span>myMidlet<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>secondCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and <strong>replace it </strong>with:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">CanvasSlideFx fxCanvas <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CanvasSlideFx<span style="color: #009900;">&#40;</span>
	Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span>myMidlet<span style="color: #009900;">&#41;</span>,
	secondCanvas,
	<span style="color: #003399;">Canvas</span>.<span style="color: #006633;">LEFT</span>,
	500L
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Display.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span>myMidlet<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>fxCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li> and we&#8217;ve done it! <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<h3>Resources and download</h3>
<p>You can download the code explained in this article with the following links:</p>
<ul>
<li><a title="FxBaseCanvas class source code" href="http://www.jappit.com/uploads/src/FxBaseCanvas.java">FxBaseCanvas.java</a>: our base class extending Canvas</li>
<li><a title="CanvasSlideFx class source code" href="http://www.jappit.com/uploads/src/CanvasSlideFx.java">CanvasSlideFx.java</a>: the class used to implement the sliding transition</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/06/23/how-to-add-sliding-transitions-between-canvas-in-j2me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a color fading text in J2ME</title>
		<link>http://www.jappit.com/blog/2008/06/18/create-color-fading-text-in-j2me/</link>
		<comments>http://www.jappit.com/blog/2008/06/18/create-color-fading-text-in-j2me/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 11:40:54 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[j2me]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[fading]]></category>
		<category><![CDATA[forumnokia]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[transitions]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=51</guid>
		<description><![CDATA[It&#8217;s time for new effects! Today we&#8217;ll see how to implement and and use text that changes multiple colors with a fading effect. You can see it in action here: J2ME text color fade effect in action. So, let&#8217;s start defining our ColorFadeText class. The code We start defining the necessary properties: //will hold the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time for new effects! <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Today we&#8217;ll see how to implement and and use <strong>text that changes multiple colors with a fading effect</strong>. You can see it in action here: <a title="Sample midlet using ColorFadeText class" href="http://www.jappit.com/index.php?page=emulator&#038;midlet=color_fade_text">J2ME text color fade effect in action</a>.</p>
<p><img src="http://www.jappit.com/images/blog/uploads/j2me_color_fade_text.gif" alt="Color Fading Text screenshot" /></p>
<p>So, let&#8217;s start defining our <strong>ColorFadeText </strong>class.</p>
<h3>The code</h3>
<p>We start defining the necessary <strong>properties</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//will hold the colors to fade</span>
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> colors <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//duration of a single fade</span>
<span style="color: #000066; font-weight: bold;">int</span> fadeDuration <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//effect start time</span>
<span style="color: #000066; font-weight: bold;">long</span> startTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//property used to check if effect has started</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> started <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//the text to be drawn</span>
<span style="color: #003399;">String</span> text <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, we define the main <strong>constructor</strong>, that will accept the following arguments:</p>
<ul>
<li>the <strong>text </strong>to be drawn</li>
<li>an int[] array containing the <strong>colors </strong>to fade into</li>
<li>the <strong>duration </strong>of a single fade</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> ColorFadeText<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> text, <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> colors, <span style="color: #000066; font-weight: bold;">int</span> fadeDuration<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>colors.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You must define at least 1 color&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;">this</span>.<span style="color: #006633;">text</span> <span style="color: #339933;">=</span> text<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">colors</span> <span style="color: #339933;">=</span> colors<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fadeDuration</span> <span style="color: #339933;">=</span> fadeDuration<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The effect <strong>start()</strong> method will simply set the startTime value to current time and the started property to true</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	startTime <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	started <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, we have the <strong>paint()</strong> method, that will be used to paint the text on the given Graphics instance:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> paint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g, <span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y, <span style="color: #000066; font-weight: bold;">int</span> anchor<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>started<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> diff <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> module <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>diff <span style="color: #339933;">%</span> fadeDuration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> colorIndex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>diff <span style="color: #339933;">/</span> fadeDuration<span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> colors.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> midColor <span style="color: #339933;">=</span> midColor<span style="color: #009900;">&#40;</span>
			colors<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>colorIndex <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> colors.<span style="color: #006633;">length</span><span style="color: #009900;">&#93;</span>,
			colors<span style="color: #009900;">&#91;</span>colorIndex<span style="color: #009900;">&#93;</span>,
			module,
			fadeDuration
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>midColor<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>
		g.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>colors<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	g.<span style="color: #006633;">drawString</span><span style="color: #009900;">&#40;</span>text, x, y, anchor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The following utility method will be the one actually used <strong>to get the current text color</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> midColor<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> color1, <span style="color: #000066; font-weight: bold;">int</span> color2, <span style="color: #000066; font-weight: bold;">int</span> prop, <span style="color: #000066; font-weight: bold;">int</span> max<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">int</span> red <span style="color: #339933;">=</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> prop <span style="color: #339933;">+</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color2 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> prop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> max<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> green <span style="color: #339933;">=</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> prop <span style="color: #339933;">+</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color2 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> prop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> max<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> blue <span style="color: #339933;">=</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> prop <span style="color: #339933;">+</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color2 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> 0xff<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> prop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> max<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> color <span style="color: #339933;">=</span> red <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">16</span> <span style="color: #339933;">|</span> green <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">8</span> <span style="color: #339933;">|</span> blue<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> color<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>How to use it?</h3>
<p>Using the <strong>ColorFadeText </strong>object is quite simple, since it&#8217;ll be very similar to use a common String. Just follow this plain steps.</p>
<p><strong>1. </strong><strong>Create </strong>a ColorFadeText instance</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ColorFadeText text <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ColorFadeText<span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;I'M A FADING TEXT!&quot;</span>,
	<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>0xff0000, 0x00ff00, 0x0000ff, 0xff00ff<span style="color: #009900;">&#125;</span>,
	<span style="color: #cc66cc;">1000</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>2. </strong><strong>Start </strong>it&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">text.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>3. </strong>And then, in your Canvas paint() method, <strong>paint </strong>it, using the same arguments used by Graphics drawString() method (adding a reference to the Graphics instance of course):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">text.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g,
	getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>,
	<span style="color: #cc66cc;">2</span>,
	<span style="color: #003399;">Graphics</span>.<span style="color: #006633;">HCENTER</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">TOP</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just a side note: since it&#8217;s an animated effect, you&#8217;ll need to <strong>repaint it quite frequently</strong>, so, for example, you can use a Thread to periodically call Canvas repaint() method.</p>
<h3>Source code download</h3>
<p>You can download <strong>source code </strong>of ColorFadeText, and of a sample Canvas that makes use of it:</p>
<ul>
<li><a title="ColorFadeText class source code" href="http://www.jappit.com/uploads/src/ColorFadeText.java">ColorFadeText.java</a>: main class source code</li>
<li><a title="AnimatedTextCanvas class source code" href="http://www.jappit.com/uploads/src/AnimatedTextCanvas.java">AnimatedTextCanvas.java</a>: a Canvas using the ColorFadeText object</li>
</ul>
<p>This article is also available on <strong>Forum Nokia Wiki</strong>: <a title="How to create a color fading text in Java ME" href="http://wiki.forum.nokia.com/index.php/How_to_create_a_color_fading_text_in_Java_ME" target="_blank">How to create a color fading text in Java ME</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/06/18/create-color-fading-text-in-j2me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ImageFx: J2ME image effects library</title>
		<link>http://www.jappit.com/blog/2008/06/06/imagefx-j2me-image-effects-library/</link>
		<comments>http://www.jappit.com/blog/2008/06/06/imagefx-j2me-image-effects-library/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 13:37:57 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[animations]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[image fx]]></category>
		<category><![CDATA[j2me api]]></category>
		<category><![CDATA[j2me library]]></category>
		<category><![CDATA[transitions]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=46</guid>
		<description><![CDATA[After two tutorials on Image animations in J2ME, I&#8217;ve finally decided to put together a library to easily integrate Image effects in a Java ME application. This first release is very very early, and is intended to be tested and to allow developers to give their feedbacks about it, so It&#8217;d be possible to modify [...]]]></description>
			<content:encoded><![CDATA[<p>After <a title="J2ME image sliding transitions" href="http://www.jappit.com/blog/2008/05/22/j2me-image-effects-part-2-sliding-transitions/">two</a> <a title="J2ME image explosion effect" href="http://www.jappit.com/blog/2008/05/20/let-your-images-explode-in-j2me/">tutorials</a> on Image animations in J2ME, I&#8217;ve finally decided to put together a <strong>library to easily integrate Image effects in a Java ME application</strong>. This first release is very very early, and is intended to be tested and to allow developers to give their feedbacks about it, so It&#8217;d be possible to modify and improve it.</p>
<p><img src="http://www.jappit.com/images/blog/uploads/imagefx_banner.gif" alt="ImageFx Banner" width="400" height="149" /></p>
<p>Currently supported effects are visible on the <a title="ImageFx in action" href="http://www.jappit.com/index.php?page=emulator&amp;midlet=image_fx">emulator page</a>, and are:</p>
<ul>
<li><strong>BlindsFx</strong></li>
<li><strong>ExplodeFx</strong></li>
<li><strong>PuzzleFx</strong></li>
<li><strong>ShakeFx</strong></li>
<li><strong>SlideFx</strong></li>
<li><strong>SpiralFx</strong></li>
<li><strong>WaveFx</strong></li>
<li><strong>WipeFx</strong></li>
</ul>
<h3>How to use it?</h3>
<p>Let&#8217;s start from a simple usage example. We start creating an Image, and then using it to create an AnimatedImage instance:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Image</span> baseImage <span style="color: #339933;">=</span> <span style="color: #003399;">Image</span>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/base.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
AnimatedImage animated <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AnimatedImage<span style="color: #009900;">&#40;</span>baseImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, we have created an <strong>AnimatedImage</strong>, that is the base class that will allow us to apply effects to <strong>Image</strong>s.</p>
<p>Now, we can create an effect (that will be a subclass of <strong>ImageFx</strong>) and apply it to our AnimatedImage:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageFx fx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PuzzleFx<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">8</span>, ImageFx.<span style="color: #006633;">TYPE_IN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
animated.<span style="color: #006633;">setFx</span><span style="color: #009900;">&#40;</span>fx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this example, we have chosen a <strong>PuzzleFx </strong>effect, that will show (or hide, depending on Fx type) our image piece by piece. As you can check on <a title="PuzzleFx JavaDocs" href="http://www.jappit.com/j2me/imagefx/doc/com/jappit/imagefx/fxs/PuzzleFx.html" target="_blank">JavaDocs page for PuzzleFx class</a>, first 2 arguments represent the horizontal and vertical pieces to split the Image into, while the last one is the type of the Fx itself.</p>
<p>Now, our AnimatedImage is ready to be animated. To start the animation, simply call the AnimatedImage <strong>start()</strong> method, passing as argument the <strong>effect duration in milliseconds</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">animated.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span>3000L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>About painting, you&#8217;ll simply have to call the <strong>paint()</strong> method, in a way that is really similar to Graphics drawImage():</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">animated.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">100</span>, <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">TOP</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">LEFT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, to begin using this library, you don&#8217;t really need any more infos. Just to point out some methods you can find useful in your app:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//stop() method will immediatly stop the FX</span>
fx.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//isRunning() method tells if the FX is running or not</span>
fx.<span style="color: #006633;">isRunning</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//isEnded() method tells if the FX animation is ended</span>
fx.<span style="color: #006633;">isEnded</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//and, if you want a looping effect, you can use</span>
fx.<span style="color: #006633;">setLooping</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Further information</h3>
<p>You can library JAR file here: <a title="ImageFx J2ME image effects library" href="http://www.jappit.com/uploads/j2me/ImageFx.jar">ImageFx.jar</a>. Current version requires MIDP 2.0 and CLDC 1.1 to be used (a version compatible with CLDC 1.0 will be released as soon as I&#8217;ve got time <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<p>Full API JavaDocs (still in early phase too <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) are also available <a title="ImageFx API JavaDocs" href="http://www.jappit.com/j2me/imagefx/doc/" target="_blank">here</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/06/06/imagefx-j2me-image-effects-library/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

