<?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>Et-Setera &#187; Java</title>
	<atom:link href="http://www.setera.org/category/software-development/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.setera.org</link>
	<description>Ramblings of a geek</description>
	<lastBuildDate>Sun, 15 Aug 2010 18:37:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>More iPhone Versus Java Differences</title>
		<link>http://www.setera.org/2010/08/15/more-iphone-versus-java-differences/</link>
		<comments>http://www.setera.org/2010/08/15/more-iphone-versus-java-differences/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 18:36:59 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=264</guid>
		<description><![CDATA[In my previous entries, I&#8217;ve discussed a few things that caught me off guard while learning iPhone development.  In the last couple of weeks, I&#8217;ve picked up an Android device to dig into that platform a bit and probably will spend less time playing with iPhone development.  Before I move too far away from iPhone, [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.setera.org/2010/04/25/iphone-versus-exceptions/">previous</a> <a href="http://www.setera.org/2010/03/07/still-a-geek/">entries</a>, I&#8217;ve discussed a few things that caught me off  guard while learning iPhone development.  In the last couple of weeks,  I&#8217;ve picked up an Android device to dig into that platform a bit and probably will spend less time playing with iPhone development.   Before I move too far away from iPhone, I wanted to wrap up the  remaining differences I found interesting between the iPhone and Java platforms.</p>
<p><span id="more-264"></span></p>
<h2>Run Loop Required for Networking</h2>
<p>One of the earliest things I needed to do was build out the networking code for my Daap player.  Initially, I was building this code as a standard Macintosh command-line application.  I happily wrote code to set up a synchronous networking call using NSURL and NSURLConnection and then&#8230; nothing.  Unlike Java, it was necessary to have a &#8220;run loop&#8221; executing.  Had I done this test initially on the iPhone emulator, I would have never run across this since the iPhone has a run loop executing the application.</p>
<h2>Subclassing and Class Clusters</h2>
<p>In Java, it is not possible to add functionality to another class.  The only real available option is to subclass the class of interest.  In general, that works ok until you get a class like java.lang.String that isn&#8217;t mean to be subclassed, in which case you need to provide some kind of wrapper or utility class.  My first attempt at adding some new functionality to NSMutableDictionary from the Foundation library was using a subclass.  I was greeted at runtime by an error similar to:</p>
<p><em>2010-08-14 09:55:48.965 TestProject[1136:207] *** Terminating app due to uncaught exception &#8216;NSInvalidArgumentException&#8217;, reason: &#8216;*** -[NSDictionary objectForKey:]: method only defined for abstract class.  Define -[MyDictionarySubclass objectForKey:]!&#8217;<br />
</em></p>
<p>What the heck?  It turns out that most of the collection classes in iPhone are implemented as class clusters.  According to the <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html">Cocoa Fundamentals Guide</a> class clusters</p>
<p><em>&#8230; group a number of private, concrete subclasses under a  public, abstract superclass. The grouping of classes in this way  simplifies the publicly visible architecture of an object-oriented  framework without reducing its functional richness.</em></p>
<p>Had I really needed to subclass NSMutableDictionary, <a href="http://cocoawithlove.com/2008/12/ordereddictionary-subclassing-cocoa.html">Matt Gallagher talks about how to create such a subclass</a>.  In my case, it turns out what I really needed was just an Objective-C category to add methods to NSMutableDictionary directly rather than subclassing the class.  Categories remind me of similar functionality available in Smalltalk, allowing additional methods to be attached to classes.  The class &#8220;shape&#8221; (instance variables) cannot be changed using categories, but new methods can be added which is very helpful for creating utility methods on a specific class rather than having to do it on a separate class.  Looking around the documentation for the various frameworks in the system, it is amazing to see how many classes are extended using categories.</p>
<h2>Summary</h2>
<p>Although my Daap player is nowhere near complete, the project did offer me plenty of visibility into Objective-C and iPhone development.  Objective-C and, in particular, the various libraries for iPhone development are incredibly powerful.  While there were a few growing pains along the way, the transition to doing iPhone development was relatively straightforward and enjoyable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2010/08/15/more-iphone-versus-java-differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Versus Exceptions</title>
		<link>http://www.setera.org/2010/04/25/iphone-versus-exceptions/</link>
		<comments>http://www.setera.org/2010/04/25/iphone-versus-exceptions/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 00:55:15 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=249</guid>
		<description><![CDATA[I&#8217;m continuing to make slow forward progress with my DAAP-based music player for the iPhone.  My most recent changes have taken this in the direction of being much more like the standard music player functionality on the iPhone.  In particular, I&#8217;ve switched over to using a tab view controller for the major perspectives of viewing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m continuing to make slow forward progress with my DAAP-based music player for the iPhone.  My most recent changes have taken this in the direction of being much more like the standard music player functionality on the iPhone.  In particular, I&#8217;ve switched over to using a tab view controller for the major perspectives of viewing the music database.</p>
<p><span id="more-249"></span></p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 424px"><a href="http://www.setera.org/wp-content/uploads/2010/04/mainscreen.png"><img class="size-full wp-image-250" title="Tab Based Main View" src="http://www.setera.org/wp-content/uploads/2010/04/mainscreen.png" alt="" width="414" height="770" /></a><p class="wp-caption-text">Tab Based Main View</p></div>
<p>In addition, there is now a (very) rudimentary <em>Now Playing</em> screen to control playback.</p>
<div id="attachment_251" class="wp-caption aligncenter" style="width: 424px"><a href="http://www.setera.org/wp-content/uploads/2010/04/nowplaying.png"><img class="size-full wp-image-251" title="Now Playing View" src="http://www.setera.org/wp-content/uploads/2010/04/nowplaying.png" alt="Now Playing View" width="414" height="770" /></a><p class="wp-caption-text">Now Playing View</p></div>
<h2>iPhone Versus Exceptions</h2>
<p>In my <a href="http://www.setera.org/2010/03/07/still-a-geek/">last entry</a>, I mentioned that I&#8217;ve struggled through some interesting differences when dealing with iPhone development when compared to my years of experience in Java.  As a long time Java developer, I&#8217;m very accustomed to the use of checked exceptions.   Most, if not all, error handling in Java is handled through the creation, throwing and catching of exceptions.  I&#8217;m accustomed to catching/handling exceptions from the underlying libraries as well as creating and  throwing my own exceptions.  It was with that background that I approached iPhone development and quickly found out that is not the recommended way of handling error conditions.  While, the standard try/catch functionality is supported in Objective-C, the documentation for Cocoa development makes it clear that using exceptions should be avoided:</p>
<p><em><strong>Important</strong>: You should reserve the use of exceptions for programming or unexpected runtime errors such as out-of-bounds collection access, attempts to mutate immutable objects, sending an invalid message, and losing the connection to the window server. You usually take care of these sorts of errors with exceptions when an application is being created rather than at runtime.</em></p>
<p><em>Instead of exceptions, error objects (NSError) and the Cocoa error-delivery mechanism are the recommended way to communicate expected errors in Cocoa applications. </em></p>
<p>This is an important difference to understand when transitioning to Cocoa development from Java development.  While this is important to understand when making calls to library methods and functions, it must also be considered when defining your own calling conventions and libraries.  In order to remain consistent, it is important to use the pattern of NSError usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2010/04/25/iphone-versus-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse MTJ &#8211; Help Wanted</title>
		<link>http://www.setera.org/2009/09/19/eclipse-mtj-help-wanted/</link>
		<comments>http://www.setera.org/2009/09/19/eclipse-mtj-help-wanted/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 18:43:17 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[EclipseME]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Tools for Java]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=212</guid>
		<description><![CDATA[Given Motorola&#8217;s push into the Android space, it comes as no surprise that they are trimming down the number of developers on the Eclipse Mobile Tools for Java project.  MTJ project lead, Christian Kurzke, announced via the mailing list that three of the key &#8220;Motorola sponsored&#8221; developers have been reassigned to a different project and [...]]]></description>
			<content:encoded><![CDATA[<p>Given <a href="http://www.motorola.com/Consumers/US-EN/Consumer-Product-and-Services/Mobile-Phones/ci.Motorola-CLIQ-US-EN.services">Motorola&#8217;s push into the Android space</a>, it comes as no surprise that they are trimming down the number of developers on the Eclipse Mobile Tools for Java project.  MTJ project lead, Christian Kurzke, <a href="http://dev.eclipse.org/mhonarc/lists/dsdp-mtj-dev/msg01352.html">announced via the mailing list</a> that three of the key &#8220;Motorola sponsored&#8221; developers have been reassigned to a different project and will no longer be sponsored to develop the Eclipse MTJ features.  The good news is that Gustavo, Diego and David have expressed interest in continuing to be involved as individual contributors.  In addition, Jon Deardon from Research In Motion will most likely be joining the list of official contributors very soon.</p>
<p>As Christian pointed out via his email, now would be an excellent time to consider getting involved in the Eclipse MTJ project.  Even something as simple as being involved on the mailing list can help us out.  If you are a mobile developer using Eclipse Mobile Tools for Java, consider contributing a patch to provide a cool new feature or to fix the bug that annoys you the most.  Not a developer, but still want to contribute?  We can always use help with documentation and project marketing.  Pitch in and lend a hand!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2009/09/19/eclipse-mtj-help-wanted/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cool BlackBerry API Support</title>
		<link>http://www.setera.org/2009/07/21/cool-blackberry-api-support/</link>
		<comments>http://www.setera.org/2009/07/21/cool-blackberry-api-support/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 00:23:19 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=157</guid>
		<description><![CDATA[In my last post, I was pretty negative about the available BlackBerry user interface controls.  While that fact hasn&#8217;t changed, I didn&#8217;t want to leave the impression that the BlackBerry API&#8217;s provide nothing to developers.  The API&#8217;s provide lots of interesting functions including the ability to extend menus within other applications.  Take a look at [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.setera.org/2009/07/13/the-woeful-state-of-blackberry-ui-controls/">last post</a>, I was pretty negative about the available BlackBerry user interface controls.  While that fact hasn&#8217;t changed, I didn&#8217;t want to leave the impression that the BlackBerry API&#8217;s provide nothing to developers.  The API&#8217;s provide lots of interesting functions including the ability to extend menus within other applications.  Take a look at the following from the default messaging application on a 4.5 device.</p>
<div id="attachment_155" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.setera.org/wp-content/uploads/2009/07/facebook1.png"><img class="size-full wp-image-155" title="Before Facebook Installation" src="http://www.setera.org/wp-content/uploads/2009/07/facebook1.png" alt="Before Facebook Installation" width="320" height="240" /></a><p class="wp-caption-text">Before Facebook Installation</p></div>
<p>This shows the menu in this application before installing the Facebook application.  After installation, you can see that the Facebook application has added a new menu item to this application.</p>
<div id="attachment_156" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.setera.org/wp-content/uploads/2009/07/facebook2.png"><img class="size-full wp-image-156" title="After Facebook Installation" src="http://www.setera.org/wp-content/uploads/2009/07/facebook2.png" alt="After Facebook Installation" width="320" height="240" /></a><p class="wp-caption-text">After Facebook Installation</p></div>
<p>This is a pretty nice feature of the API.  Although I don&#8217;t have actual code to show for this, my assumption is that this is provided by using:</p>
<ul>
<li><a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/blackberry/api/menuitem/ApplicationMenuItem.html">ApplicationMenuItem</a></li>
<li><a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/blackberry/api/menuitem/ApplicationMenuItemRepository.html">ApplicationMenuItemRepository</a>
<ul>
<li><a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/blackberry/api/menuitem/ApplicationMenuItemRepository.html#MENUITEM_MESSAGE_LIST">MENUITEM_MESSAGE_LIST</a></li>
</ul>
</li>
</ul>
<p>API&#8217;s like this allow for incredible integration with the rest of the applications on the device, opening up many very interesting opportunities.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2009/07/21/cool-blackberry-api-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Galileo Released &#8211; MTJ 1.0 Joins The Train</title>
		<link>http://www.setera.org/2009/06/24/eclipse-galileo-released-mtj-1-0-joins-the-train/</link>
		<comments>http://www.setera.org/2009/06/24/eclipse-galileo-released-mtj-1-0-joins-the-train/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 02:46:25 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Tools for Java]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=127</guid>
		<description><![CDATA[The Eclipse Project has released version 3.5 of the Eclipse platform as part of the Galileo Release Train.  There are announcements and discussions all over the place, like here, here and here.  The question is where is the love for the Mobile Tools for Java?  The Galileo release marks the graduation of the Mobile Tools [...]]]></description>
			<content:encoded><![CDATA[<p>The Eclipse Project has released version 3.5 of the Eclipse platform as part of the Galileo Release Train.  There are announcements and discussions all over the place, like <a href="http://blogs.zdnet.com/Burnette/?p=1276">here</a>, <a href="http://feedproxy.google.com/~r/eclipse/fnews/~3/HIZ81R9YCH4/20090624_galileo.php">here</a> and <a href="http://alblue.blogspot.com/2009/06/eclipse-galileo-released.html">here</a>.  The question is where is the love for the <a href="http://www.eclipse.org/dsdp/mtj/">Mobile Tools for Java</a>?  The Galileo release marks the graduation of the <a href="http://www.eclipse.org/dsdp/mtj/">Mobile Tools for Java</a> project from incubation, providing a solid set of tools for JavaME development in Eclipse.  The involvement from the various member companies has been excellent during the development of MTJ and transition from EclipseME.  I have to admit that I&#8217;m a bit disappointed at the lack of coverage of the release.  Pass the word that MTJ is <em><strong>the</strong></em> way to develop for JavaME.</p>
<p>The Pulsar project also saw an initial early release with Galileo.  I will provide some background on this project in an upcoming post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2009/06/24/eclipse-galileo-released-mtj-1-0-joins-the-train/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZBerry Story Library</title>
		<link>http://www.setera.org/2009/06/21/zberry-story-library/</link>
		<comments>http://www.setera.org/2009/06/21/zberry-story-library/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 00:18:40 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ZBerry]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=122</guid>
		<description><![CDATA[I&#8217;ve decided to dub this little hobby project ZBerry (BlackBerry Z-Machine Interpreter).  I made some progress this weekend allowing stories to be selected from the file system via a new &#8220;library&#8221; view. I need to add some suspend/resume support before this thing becomes really very usable on a phone, but some progress anyway&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to dub this little hobby project <em><strong>ZBerry</strong></em> (BlackBerry Z-Machine Interpreter).  I made some progress this weekend allowing stories to be selected from the file system via a new &#8220;library&#8221; view.</p>
<div id="attachment_124" class="wp-caption aligncenter" style="width: 342px"><a href="http://www.setera.org/wp-content/uploads/2009/06/library.png"><img class="size-full wp-image-124" title="ZBerry Library Selection" src="http://www.setera.org/wp-content/uploads/2009/06/library.png" alt="ZBerry Library Selection" width="332" height="285" /></a><p class="wp-caption-text">ZBerry Library Selection</p></div>
<p>I need to add some suspend/resume support before this thing becomes really very usable on a phone, but some progress anyway&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2009/06/21/zberry-story-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BlackBerry drawText Alignment and Anchors</title>
		<link>http://www.setera.org/2009/06/15/blackberry-drawtext-alignment-and-anchors/</link>
		<comments>http://www.setera.org/2009/06/15/blackberry-drawtext-alignment-and-anchors/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 02:10:55 +0000</pubDate>
		<dc:creator>Craig Setera</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.setera.org/?p=80</guid>
		<description><![CDATA[I was recently struggling to understand how to text alignment works with the BlackBerry Graphics drawText function.  Having developed for MIDP on JavaME for a number of years, I found that the way the BlackBerry API works is a bit counter-intuitive until you understand how it works.  I expected that this code would work, based [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently struggling to understand how to text alignment works with the BlackBerry Graphics drawText function.  Having developed for MIDP on JavaME for a number of years, I found that the way the BlackBerry API works is a bit counter-intuitive until you understand how it works.  I expected that this code would work, based on JavaME:</p>
<p><span id="more-80"></span></p>
<blockquote><p>protected void paint(Graphics graphics) {<br />
// Stash the current colors and invert them for the<br />
// background fill<br />
int currentBgColor = graphics.getBackgroundColor();<br />
int currentFgColor = graphics.getColor();<br />
int w = getWidth();<br />
int h = getHeight();</p>
<p>graphics.setColor(currentFgColor);<br />
graphics.fillRect(0, 0, w, h);</p>
<p>graphics.setColor(currentBgColor);<br />
graphics.setBackgroundColor(currentFgColor);</p>
<p>// Draw the pieces of text<br />
int midHeight = h / 2;<br />
int midWidth = w / 2;<br />
buffer = new StringBuffer();<br />
buffer.setLength(0);<br />
buffer.append(&#8220;Moves: &#8220;).append(moves);<br />
graphics.drawText(<br />
buffer, 0, buffer.length(), w, midHeight, Graphics.VCENTER | Graphics.RIGHT, w);</p>
<p>buffer.setLength(0);<br />
buffer.append(&#8220;Score: &#8220;).append(score);<br />
graphics.drawText(<br />
buffer, 0, buffer.length(), midWidth, midHeight, Graphics.VCENTER | Graphics.HCENTER, w);</p>
<p>graphics.drawText(statusText, 0, midHeight, Graphics.VCENTER | Graphics.LEFT);<br />
}</p></blockquote>
<p>I had expected three pieces of text, aligned right, left and center.  Instead, I ended up with:</p>
<div id="attachment_93" class="wp-caption aligncenter" style="width: 339px"><a href="http://www.setera.org/wp-content/uploads/2009/06/alignment1.png"><img class="size-full wp-image-93" title="Broken Text Alignment" src="http://www.setera.org/wp-content/uploads/2009/06/alignment1.png" alt="Broken Text Alignment" width="329" height="288" /></a><p class="wp-caption-text">Broken Text Alignment</p></div>
<p>The <em><strong>Graphics#drawText</strong></em> methods look similar to:</p>
<blockquote><p>public int <strong>drawText</strong>(StringBuffer text,<br />
int offset,<br />
int len,<br />
int x,<br />
int y,<br />
int flags,<br />
int width)</p></blockquote>
<p>The trick with this API has to do with that last parameter.  The <em><strong>width</strong></em> parameter is used to define a bounding box.  The <em><strong>x</strong></em> and <em><strong>y</strong></em> parameters define the top-left corner of that bounding box.  Horizontal alignment flags (<strong>HCENTER</strong> and <strong>RIGHT</strong>) do the alignment relative to the bounding box defined by <em>(x, y, x + width, y + height)</em>.  To get the same behavior I had expected, I needed to set the bounding box to include the complete width and then specify those alignment flags.  The correct code now looks more like the following:</p>
<blockquote><p><code><br />
protected void paint(Graphics graphics) {<br />
// Stash the current colors and invert them for the<br />
// background fill<br />
int currentBgColor = graphics.getBackgroundColor();<br />
int currentFgColor = graphics.getColor();<br />
int w = getWidth();<br />
int h = getHeight();</code></p>
<p>graphics.drawText(<br />
statusText,<br />
padding,<br />
midHeight,<br />
Graphics.VCENTER | Graphics.LEFT);<br />
}</p>
<p>graphics.setColor(currentFgColor);<br />
graphics.fillRect(0, 0, w, h);</p>
<p>graphics.setColor(currentBgColor);<br />
graphics.setBackgroundColor(currentFgColor);</p>
<p>// Draw the pieces of text<br />
int midHeight = h / 2;<br />
int paddedWidth = w &#8211; (2 * padding);</p>
<p>buffer = new StringBuffer();<br />
buffer.setLength(0);<br />
buffer.append(&#8220;Moves: &#8220;).append(moves);<br />
graphics.drawText(<br />
buffer,<br />
0,<br />
buffer.length(),<br />
padding,<br />
midHeight,<br />
Graphics.VCENTER | Graphics.RIGHT,<br />
paddedWidth);</p>
<p>buffer.setLength(0);<br />
buffer.append(&#8220;Score: &#8220;).append(score);<br />
graphics.drawText(<br />
buffer,<br />
0,<br />
buffer.length(),<br />
padding,<br />
midHeight,<br />
Graphics.VCENTER | Graphics.HCENTER,<br />
paddedWidth);</p>
<p>}</p></blockquote>
<p>This results in expected text layout:</p>
<div id="attachment_94" class="wp-caption aligncenter" style="width: 339px"><a href="http://www.setera.org/wp-content/uploads/2009/06/alignment2.png"><img class="size-full wp-image-94" title="Correct Text Alignment" src="http://www.setera.org/wp-content/uploads/2009/06/alignment2.png" alt="Correct Text Alignment" width="329" height="288" /></a><p class="wp-caption-text">Correct Text Alignment</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.setera.org/2009/06/15/blackberry-drawtext-alignment-and-anchors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
