<?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>Silveira Neto &#187; JavaFX</title>
	<atom:link href="http://silveiraneto.net/tag/javafx/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:13:27 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tomorrow Java</title>
		<link>http://silveiraneto.net/2009/08/29/tomorrow-java/</link>
		<comments>http://silveiraneto.net/2009/08/29/tomorrow-java/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 01:28:53 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[CEJUG]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Tomorrow Java]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2747</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/08/29/tomorrow-java/" title="Tomorrow Java"></a>Como prometido, palestra que eu e o Rafael Carneiro fizemos para apresentar no Café com Tapioca desse mês. Tomorrow Java View more documents from José Maria Silveira Neto. Update: O Paulo Jr também fez uma cobertura do evento e da &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/08/29/tomorrow-java/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/08/29/tomorrow-java/" title="Tomorrow Java"></a><p>Como prometido, palestra que eu e o Rafael Carneiro fizemos para apresentar no <a href="http://cejug.org/pages/viewpage.action?pageId=42172419">Café com Tapioca desse mês</a>. </p>
<p><center>
<div style="width:425px;text-align:left" id="__ss_1925427"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/silveiraneto/tomorrow-java" title="Tomorrow Java">Tomorrow Java</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tomorowjavacctago2009-090829201329-phpapp01&#038;stripped_title=tomorrow-java" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tomorowjavacctago2009-090829201329-phpapp01&#038;stripped_title=tomorrow-java" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/silveiraneto">José Maria Silveira Neto</a>.</div>
</div>
<p></center></p>
<p><strong>Update:</strong> O <a href="http://www.paulojdev.com.br/">Paulo Jr</a> <a href="http://www.paulojdev.com.br/2009/08/palestra-cejug-agosto/">também fez uma cobertura</a> do evento e da apresentação dele.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/08/29/tomorrow-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaFX on Linux!</title>
		<link>http://silveiraneto.net/2009/06/02/javafx-on-linux/</link>
		<comments>http://silveiraneto.net/2009/06/02/javafx-on-linux/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 02:10:11 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MacOS X]]></category>
		<category><![CDATA[Opensolaris]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2649</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/06/02/javafx-on-linux/" title="JavaFX on Linux!"></a>Yeah. No more workarounds. Download now JavaFX 1.2 for Windows, MacOS X, Linux and OpenSolaris! \o/ There&#8217;s also a lots of improvements in the language and the API. For details on that read this document. Unfortunately, as a side effect &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/06/02/javafx-on-linux/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/06/02/javafx-on-linux/" title="JavaFX on Linux!"></a><p>Yeah. No more workarounds. <a title="Get JavaFX" href="http://javafx.com/downloads">Download now JavaFX 1.2 for Windows, MacOS X, Linux and OpenSolaris!</a></p>
<p><center><img title="bob sponja dancinha" src="http://silveiraneto.net/wp-content/uploads/2009/06/bob_sponja_dancinha.gif" alt="bob sponja dancinha" width="275" height="200" /></center></p>
<p>\o/</p>
<p>There&#8217;s also a lots of improvements in the language and the API. For details on that <a href="http://www.javafx.com/docs/articles/javafx1-2.jsp">read this document</a>. Unfortunately, as a side effect of those great changes some JavaFX source codes posted here are now deprecated and need a few changes to compile again but the online preview of them as applet or Java Web Start will continue to work well.</p>
<p>Let&#8217;s code.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/06/02/javafx-on-linux/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>FootprintFX</title>
		<link>http://silveiraneto.net/2009/06/02/footprintfx/</link>
		<comments>http://silveiraneto.net/2009/06/02/footprintfx/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 04:53:28 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[Felipe Gaúcho]]></category>
		<category><![CDATA[Footprint]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2646</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/06/02/footprintfx/" title="FootprintFX"></a>Footprint is a publisher and distributor of certificates of participation in conferences &#8211; signed PDF documents that prove you attended a conference or a course. This is a little JavaFX application that shows how to create a interface that displays &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/06/02/footprintfx/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/06/02/footprintfx/" title="FootprintFX"></a><p style="text-align: center;"><img class="size-full wp-image-2647 aligncenter" title="Footprint logo" src="http://silveiraneto.net/wp-content/uploads/2009/06/footprintlogo.jpg" alt="Footprint logo" width="109" height="80" /></p>
<p><a title="Footprint" href="https://footprint.dev.java.net/">Footprint</a> is a publisher and distributor of certificates of participation in conferences &#8211; signed PDF documents that prove you attended a conference or a course.</p>
<p>This is a little JavaFX application that shows how to create a interface that displays data provided by services. This version uses three services: one that counts the number of users, other that counts the number of events and one that list these events. Check out the <a title="JAVAFX Source Code " href="http://silveiraneto.net/downloads/javafx/footprintfx/src/footprintfx/Main.fx">source code here</a>.  Try the application as a draggable <a title="JavaFX" href="http://silveiraneto.net/downloads/javafx/footprintfx/dist/footprintfx.html">JavaFX applet here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/06/02/footprintfx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX, Retrieving non XML/JSON data from clouds</title>
		<link>http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/</link>
		<comments>http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/#comments</comments>
		<pubDate>Sun, 31 May 2009 15:34:42 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[HttpRequest]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PullParser]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Zembly]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2631</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/" title="JavaFX, Retrieving non XML/JSON data from clouds"></a>Usuually on JavaFX we grab data using HttpRequest from external resources on formats like JSON or XML. I showed how to get it on the post Reading Twitter with JavaFX and how to parse it using PullParser on the post &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/" title="JavaFX, Retrieving non XML/JSON data from clouds"></a><p style="text-align: center;"><img class="size-full wp-image-2640 aligncenter" title="weather overcast icon from the Tango Project" src="http://silveiraneto.net/wp-content/uploads/2009/05/tango_weather-overcast.png" alt="tango weather overcast" width="200" height="200" /></p>
<p>Usuually on JavaFX we grab data using <a title="JAVAFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.io.http/javafx.io.http.HttpRequest.html">HttpRequest</a> from external resources on formats like JSON or XML. I showed how to get it on the post <a title="Reading Twitter with JavaFX" href="http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/">Reading Twitter with JavaFX</a> and how to parse it using <a href="http://java.sun.com/javafx/1/docs/api/javafx.data.pull/javafx.data.pull.PullParser.html">PullParser</a> on the post <a title="Parsing XML sandwich with JavaFX" href="http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/">Parsing a XML sandwich with JavaFX</a>.</p>
<p>Another day I need to grab and interpret some plain results, not in XML nor JSON, while consuming a REST service. In this case we don&#8217;t have a well structure data so the PullParser won&#8217;t help us.</p>
<p><strong>Example 1: Reading Raw Data</strong></p>
<p>In this example we&#8217;ll load a plain text file served in a remote location.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var planetsRequest <span style="color: #339933;">=</span> HttpRequest <span style="color: #009900;">&#123;</span>
    location<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://silveiraneto.net/downloads/planets&quot;</span><span style="color: #339933;">;</span>
    onInput<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">:</span> <span style="color: #003399;">InputStream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var buff <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        var line <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> buff.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            println<span style="color: #009900;">&#40;</span>line<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>
planetsRequest.<span style="color: #006633;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will produce the output:</p>
<blockquote><p>Mercury<br />
Venus<br />
Earth<br />
Mars<br />
Jupiter<br />
Saturn<br />
Uranus<br />
Neptune</p></blockquote>
<p><strong>Example 2: </strong><strong>Discovering your IP Address</strong></p>
<p>In this example we&#8217;ll examine how to integrate a request of a remote data in a running graphical program.</p>
<p>The best way to know your real IP address is asking for a remote server to look which IP made that request. It&#8217;s like calling for a friend and asking him which number appeared in his mobile. =) This <a href="http://en.wikipedia.org/wiki/Server-side">server side</a> Python script prints the IP address of who requested the page.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: text/html&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">environ</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'REMOTE_ADDR'</span><span style="color: black;">&#93;</span></pre></div></div>

<p>In the client side, with JavaFX, we&#8217;ll load the remote value into a local variable. The <em>ip</em> is assigned with the value &#8220;&#8230;&#8221; and later the ipRequest will replace it with a String with the IP. The <em>bind</em> feature will automatically fix the GUI String text.</p>
<p>For the user he will see the ellipsis for a few seconds and so their IP.</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;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.text.Text</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.io.http.HttpRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
&nbsp;
var ip <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;...&quot;</span><span style="color: #339933;">;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;What is my IP?&quot;</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">80</span>
    scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> Text <span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>, y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span>
            content<span style="color: #339933;">:</span> bind <span style="color: #0000ff;">&quot;My IP is {ip}&quot;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var ipRequest <span style="color: #339933;">=</span> HttpRequest <span style="color: #009900;">&#123;</span>
    location<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://silveiraneto.net/scripts/myip.py&quot;</span><span style="color: #339933;">;</span>
    onInput<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">:</span> <span style="color: #003399;">InputStream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var buff <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ip <span style="color: #339933;">=</span> buff.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
ipRequest.<span style="color: #006633;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can try this <a href="http://silveiraneto.net/downloads/javafx/myip/MyIP.html">JavaFX applet here</a>.</p>
<p><strong>Example 3: </strong><strong>Reading Integer values</strong></p>
<p>Until now we handled just plain Strings. But in some cases you want to get number as non structured data. In this case you need to know previously which type the data is. In the case of a web service this probably will be described in a <a href="http://www.w3.org/TR/wsdl">WSDL file</a>.</p>
<p>Here I&#8217;m writing a very simple service script at <a href="http://zembly.com">Zembly</a>, a great platform for cloud computing. It&#8217;s called aplusb, it justs add the first parameter A to the second B.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Parameters.<span style="color: #660066;">a</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>Parameters.<span style="color: #660066;">b</span><span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">return</span> Parameters.<span style="color: #660066;">a</span><span style="color: #339933;">+</span>Parameters.<span style="color: #660066;">b</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The service is <a href="http://zembly.com/things/1827f696529d4e6f940c36e8e79bea1c#">published at Zembly here</a> where you can see more details on how to invoke it.</p>
<p>A simple way to invoke it on JavaFX and than getting the value as an Integer:</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;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.io.http.HttpRequest</span><span style="color: #339933;">;</span>
&nbsp;
var a <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
var b <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
var result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> on replace <span style="color: #009900;">&#123;</span>
    println<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var zemblyRequest <span style="color: #339933;">=</span> HttpRequest <span style="color: #009900;">&#123;</span>
    location<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://zembly.net/things/1827f696529d4e6f940c36e8e79bea1c;exec?a={a}&amp;amp;b={b}&quot;</span><span style="color: #339933;">;</span>
    onInput<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">:</span> <span style="color: #003399;">InputStream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var buff <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>buff.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
zemblyRequest.<span style="color: #006633;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The output will be:</p>
<blockquote><p>0<br />
300</p></blockquote>
<p>The first 0 is from the first assignment on the var result. The 300 is from the webservice itself.</p>
<p>The same approach can be used to convert the ASCII/Unicode result from the stream to the suitable type on a variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/05/31/javafx-retrieving-non-xmljson-data-from-clouds/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JavaFX 1.1 for Linux workaround</title>
		<link>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/</link>
		<comments>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/#comments</comments>
		<pubDate>Sat, 16 May 2009 11:53:15 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[HuaSong Liu]]></category>
		<category><![CDATA[jaunty jackalope]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[javafx4linux]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Kaesar Alnijres]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Weiqi Gao]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2581</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/" title="JavaFX 1.1 for Linux workaround "></a>Download javafx4linux.tar.bz2 (~ 36Mb). Installing 1) Extract the javafx4linux.tar.bz2 file. In this example I&#8217;m placing it on my Desktop. After the installing process you can remove it. 2) Open your NetBeans 6.5 and go at Tools → Plugins and go &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/" title="JavaFX 1.1 for Linux workaround "></a><p><strong>Download</strong></p>
<blockquote><p><a title="JavaFX for Linux" href="http://silveiraneto.net/downloads/javafx4linux.tar.bz2">javafx4linux.tar.bz2</a> (~ 36Mb).</p></blockquote>
<p><strong>Installing</strong></p>
<p>1) Extract the javafx4linux.tar.bz2 file. In this example I&#8217;m placing it on my Desktop. After the installing process you can remove it.</p>
<p style="text-align: center;"><strong><a href="http://silveiraneto.net/wp-content/uploads/2009/05/javafx_linux_ubuntu_extract.png"><img class="size-medium wp-image-2593 aligncenter" title="javafx linux ubuntu extract" src="http://silveiraneto.net/wp-content/uploads/2009/05/javafx_linux_ubuntu_extract-500x312.png" alt="javafx linux ubuntu extract" width="500" height="312" /></a><br />
</strong></p>
<p>2) Open your NetBeans 6.5 and go at <em>Tools</em> → <em>Plugins</em> and go to <em>Downloaded</em> tab. In a plain and new NetBeans installation there will be no plugin in this tab yet.</p>
<p style="text-align: center;"><strong><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step01.png"><img class="alignnone size-medium wp-image-2582" title="netbeans javafx linux step01" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step01-500x312.png" alt="netbeans javafx linux step01" width="500" height="312" /></a><br />
</strong></p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step02.png"><img class="size-medium wp-image-2583 aligncenter" title="netbeans javafx linux step02" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step02-500x312.png" alt="netbeans javafx linux step02" width="500" height="312" /></a></p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step03.png"><img class="size-medium wp-image-2584 aligncenter" title="netbeans javafx linux step03" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step03-500x312.png" alt="netbeans javafx linux step03" width="500" height="312" /></a></p>
<p>3) Click on the <em>Add Plugins</em> button and head to the directory you extracted the file and select all .nbm files.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step04.png"><img class="size-medium wp-image-2585 aligncenter" title="netbeans javafx linux step 04" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step04-500x312.png" alt="netbeans javafx linux step 04" width="500" height="312" /></a></p>
<p>4) You will see a list of 22 plugins selected. Click on the <em>Install</em> button.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step05.png"><img class="size-medium wp-image-2586 aligncenter" title="netbeans javafx linux step 05" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step05-500x312.png" alt="netbeans javafx linux step 05" width="500" height="312" /></a></p>
<p>5) Just keep clicking on the <em>Next</em> button.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step06.png"><img class="size-medium wp-image-2587 aligncenter" title="netbeans javafx linux step 6" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step06-500x312.png" alt="netbeans javafx linux step 6" width="500" height="312" /></a></p>
<p>6) Check the license agreement accept box.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step07.png"><img class="size-medium wp-image-2588 aligncenter" title="netbeans javafx linux step 7" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step07-500x312.png" alt="netbeans javafx linux step 7" width="500" height="312" /></a></p>
<p>7) You&#8217;ll see a warning because the Linux pluggin is not signed. Don&#8217;t worry, just click <em>Continue</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step08.png"><img class="size-medium wp-image-2589 aligncenter" title="netbeans javafx linux step 8" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step08-500x312.png" alt="netbeans javafx linux step 8" width="500" height="312" /></a></p>
<p>8) Click on Finish to restart NetBeans.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step09.png"><img class="size-medium wp-image-2590 aligncenter" title="netbeans javafx linux step 9" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step09-500x312.png" alt="netbeans javafx linux step 9" width="500" height="312" /></a></p>
<p>9) Now we can test it. Go at <em>File</em> → <em>New Project</em>, select the JavaFX on <em>Categories</em> and <em>JavaFX Script Application</em> on Projects.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step10.png"><img class="alignnone size-medium wp-image-2591" title="netbeans javafx linux step 10" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step10-500x312.png" alt="netbeans javafx linux step 10" width="500" height="312" /></a></p>
<p>10) Put some code and run it. There is. JavaFX on Linux.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step11.png"><img class="size-medium wp-image-2592 aligncenter" title="netbeans javafx linux step 11" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step11-500x312.png" alt="netbeans javafx linux step 11" width="500" height="312" /></a></p>
<p><strong>Considerations</strong></p>
<p>This is not a official of JavaFX for Linux! This solution was tested on Ubuntu 9.04 &#8220;Jaunty Jackalope&#8221; with Java 6 update 13 and NetBeans 6.5.1, but should also work with others Linux distributions and Java versions greater than 5.</p>
<p><strong>Known bugs</strong></p>
<p>As a non official workaround for JavaFX for Linux you may notice some drawbacks. Some parts of the JavaFX runtime rely on native implementations on the specific operational system. You may not use some multimedia capabilities as video playback, JavaFX Mobile emulator and some performance issues in some effects. Despite that, is perfectly possible to develop applications using JavaFX on NetBeans.</p>
<p><strong>Thanks</strong></p>
<p>I&#8217;d like to thanks some guys around the world. <a href="http://www.weiqigao.com/blog/2008/12/04/using_javafx_1_0_on_linux.html">Weiqi Gao&#8217;s original post on JavaFX on Linux</a>, <a href="http://java.dzone.com/tips/javafx-11-linux-netbeans">HuaSong Liu article on DZone</a> and <a href="http://java-javafx-iipt.blogspot.com/2009/03/javafx-111-netbeans-651-on-linux.html">Kaesar Alnijres post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JavaFX, Acessando Recursos de Dentro do JAR</title>
		<link>http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/</link>
		<comments>http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 19:59:27 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[português]]></category>
		<category><![CDATA[fileinputstream]]></category>
		<category><![CDATA[imageview]]></category>
		<category><![CDATA[JAR]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[sanduíche]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2477</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/" title="JavaFX, Acessando Recursos de Dentro do JAR"></a>Translation: there&#8217;s a English version of this article. Para algumas classes como o javafx.scene.image.Image é fácil abrir imagens de uma localidade remotada com: ImageView &#123; image: Image &#123; url: &#34;http://example.com/minhaFigura.png&#34; &#125; &#125; ou uma imagem local com a constante __DIR: &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/" title="JavaFX, Acessando Recursos de Dentro do JAR"></a><blockquote><p><img src="http://silveiraneto.net/wp-content/uploads/2008/10/us.png" alt="us flag" /><small><strong>Translation:</strong> there&#8217;s a <a href="http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/">English version</a> of this article.</small></p></blockquote>
<p>Para algumas classes como o <a href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.Image.html">javafx.scene.image.Image</a> é fácil abrir imagens de uma localidade remotada com:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://example.com/minhaFigura.png&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ou uma imagem local com a constante __DIR:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}/minhaFigura.png&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Mas para outras classes abrir recursos internos (de dentro do próprio arquivo jar) não é tão direto. Por exemplo, no artigo <a title="JavaFX XML" href="http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/">Parsing a XML Sandwich with JavaFX</a> eu tive que colocar o arquvio XML dentro de um diretório temporário. Uma maneira mais elegante teria sido:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">handlexml</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Resource<span style="color: #009900;">&#123;</span>
    function getUrl<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    function getStream<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var list <span style="color: #339933;">=</span> SwingList <span style="color: #009900;">&#123;</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">600</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#125;</span>
&nbsp;
var myparser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
    documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span><span style="color: #339933;">;</span>
    onEvent<span style="color: #339933;">:</span> function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var item <span style="color: #339933;">=</span> SwingListItem <span style="color: #009900;">&#123;</span>text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;event {e}&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        insert item into list.<span style="color: #006633;">items</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    input<span style="color: #339933;">:</span> Resource<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>.<span style="color: #006633;">getStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
myparser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Map&quot;</span>
    scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> list
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Com um simples arquivo XML chamadov<em>my.xml</em> dentro do seu pacote.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bread</span> <span style="color: #000066;">sesame</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catchup</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hamburguer</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cheese</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;chedar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maionese</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lettuce</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bread<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/04/fileplace.png" alt="fileplace" title="fileplace" width="210" height="107" class="alignnone size-full wp-image-2474" /></center><br />
E temos os mesmos resultados de antes, mas com todos seus aquivos dentro de seus Jars.<br />
<center><img alt="" src="http://silveiraneto.net/wp-content/uploads/2008/12/javafx_xml_sandwich.png" title="XML Sandwich" class="alignnone" width="625" height="354" /></center></p>
<p>Referencias:</p>
<ul>
<ol>Artigo do Hildeberto <a href="http://www.hildeberto.com/2008/12/acessing-resources-inside-of-jar-files.html">Acessing Resources Inside of JAR Files</a></ol>
<ol><a href="http://java.sun.com/javafx/1/tutorials/core/">JavaFX Core Tutorial</a></ol>
<ol>Fórum do JavaFX, <a href="http://forums.sun.com/thread.jspa?threadID=5367468&#038;tstart=2">esta</a> e <a href="http://forums.sun.com/thread.jspa?threadID=5340352">esta</a> thread.</ol>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaFX, getting resources of inside your JAR</title>
		<link>http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/</link>
		<comments>http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 19:51:54 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[fileinputstream]]></category>
		<category><![CDATA[getclass]]></category>
		<category><![CDATA[JAR]]></category>
		<category><![CDATA[jarfile]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[picture]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[sandwich]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2471</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/" title="JavaFX, getting resources of inside your JAR"></a>Tradução: há uma versão em Português desse artigo. For some classes like javafx.scene.image.Image is easy load an image from a external resource like: ImageView &#123; image: Image &#123; url: &#34;http://example.com/myPicture.png&#34; &#125; &#125; or a resource inside your own Jar file &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/" title="JavaFX, getting resources of inside your JAR"></a><blockquote><p><img src="http://silveiraneto.net/wp-content/uploads/2008/10/br.png" alt="br flag" /><small><strong>Tradução:</strong> há uma <a href="http://silveiraneto.net/2009/04/10/javafx-acessando-recursos-de-dentro-do-jar/">versão em Português</a> desse artigo.</small></p></blockquote>
<p>For some classes like <a href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.Image.html">javafx.scene.image.Image</a> is easy load an image from a external resource like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://example.com/myPicture.png&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>or a resource inside your own Jar file with the __DIR__ constant:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}/myPicture.png&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>But for other classes loading a internal resource (inside your own jarfile) is not so direct. For example, in the article <a title="JavaFX XML" href="http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/">Parsing a XML Sandwich with JavaFX</a> I had to place the XML file in a temp directory. A more elegant way would be:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">handlexml</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Resource<span style="color: #009900;">&#123;</span>
    function getUrl<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    function getStream<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var list <span style="color: #339933;">=</span> SwingList <span style="color: #009900;">&#123;</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">600</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#125;</span>
&nbsp;
var myparser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
    documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span><span style="color: #339933;">;</span>
    onEvent<span style="color: #339933;">:</span> function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var item <span style="color: #339933;">=</span> SwingListItem <span style="color: #009900;">&#123;</span>text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;event {e}&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        insert item into list.<span style="color: #006633;">items</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    input<span style="color: #339933;">:</span> Resource<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>.<span style="color: #006633;">getStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
myparser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Map&quot;</span>
    scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> list
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>With a simple XML file called <em>my.xml</em> inside your package.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bread</span> <span style="color: #000066;">sesame</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catchup</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hamburguer</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cheese</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;chedar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maionese</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lettuce</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bread<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/04/fileplace.png" alt="fileplace" title="fileplace" width="210" height="107" class="alignnone size-full wp-image-2474" /></center><br />
And we get the same result as before, but all files inside our Jars.<br />
<center><img alt="" src="http://silveiraneto.net/wp-content/uploads/2008/12/javafx_xml_sandwich.png" title="XML Sandwich" class="alignnone" width="625" height="354" /></center></p>
<p>References:</p>
<ul>
<ol>Hildeberto&#8217;s article <a href="http://www.hildeberto.com/2008/12/acessing-resources-inside-of-jar-files.html">Acessing Resources Inside of JAR Files</a></ol>
<ol><a href="http://java.sun.com/javafx/1/tutorials/core/">JavaFX Core Tutorial</a></ol>
<ol>JavaFX forum, <a href="http://forums.sun.com/thread.jspa?threadID=5367468&#038;tstart=2">this</a> and <a href="http://forums.sun.com/thread.jspa?threadID=5340352">this</a> thread.</ol>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/04/10/javafx-getting-resources-of-inside-your-jar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Aprenda JavaFX com Paixão</title>
		<link>http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/</link>
		<comments>http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 04:06:30 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[português]]></category>
		<category><![CDATA[Curso]]></category>
		<category><![CDATA[grátis]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Sang Shin]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2191</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/" title="Aprenda JavaFX com Paixão"></a>Sang Shin photo, credits by Raymundo Vázquez. Nosso amigo Sang Shin do Java Passion nos avisa que está para começar a primeira turma do curso de programação de 15 semanas em JavaFX (com paixão!) está começando. O curso é online, &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/" title="Aprenda JavaFX com Paixão"></a><p style="text-align: center;"><img class="size-full wp-image-2195 aligncenter" title="Sang Shin" src="http://silveiraneto.net/wp-content/uploads/2009/01/sang_shin.jpg" alt="Sang Shin" width="375" height="325" /><br />
<small>Sang Shin photo, credits by <a href="http://flickr.com/photos/ray_iceman/501712186/">Raymundo Vázquez</a>.</small></p>
<p>Nosso amigo <a title="Sang Shin" href="http://www.javapassion.com/SangSchedule.html">Sang Shin</a> do <a title="Site Java Passion" href="http://www.javapassion.com">Java Passion</a> nos avisa que está para começar a primeira turma do curso de programação de 15 semanas em <a href="http://javafx.com">JavaFX</a> (com paixão!) está começando. O curso é online, gratuito e começa agora dia 30 de Janeiro em 2009.</p>
<p style="text-align: center;"><a title="Site Java Passion" href="http://www.javapassion.com/"><img class="size-medium wp-image-2197 aligncenter" title="java passion" src="http://silveiraneto.net/wp-content/uploads/2009/01/java_passion-500x228.png" alt="java passion" width="500" height="228" /></a></p>
<p>Para se inscrever envie um email em branco para <a title="inscreva-se" href="mailto:javafxprogramming-subscribe@googlegroups.com">javafxprogramming-subscribe@googlegroups.com</a>. É um curso mais ou menos como qualquer outro, espera-se que os estudantes façam suas lições de casa depois de estudar as apresentações e fazer alguns laboratórios práticos mas tudo isso gratuito e online.</p>
<p>Também há uma lista onde os estudantes podem perguntar e responder perguntas. Para maiores informações, por favor visite um dos sites abaixo:</p>
<ul>
<li>Site do curso: <a href="http://www.javapassion.com/javafx">http://www.javapassion.com/javafx</a></li>
<li>Tópicos do curso: <a href="http://www.javapassion.com/javafx/#Topics">http://www.javapassion.com/javafx/#Topics</a></li>
<li>Perguntas Frequentes: <a href="http://www.javapassion.com/coursefaq.html">http://www.javapassion.com/coursefaq.html</a></li>
</ul>
<p>Lembrando a todos que os cursos do Java Passion são todos em inglês.</p>
<p>Aproveite essa oportunidade e passe a frente a notícia.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/01/18/aprenda-javafx-com-paixao/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaFX, easy use of tiles</title>
		<link>http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/</link>
		<comments>http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 14:07:38 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Pixelart]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[tileset]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2098</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/" title="JavaFX, easy use of tiles"></a>Continuing my little JavaFX framework for game development, right now focused on use those tiles I&#8217;m drawing and posting here in my blog. This framework will be a group of classes for simplify and hide some complexities of common game &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/" title="JavaFX, easy use of tiles"></a><p>Continuing my little JavaFX framework for game development, right now focused on use those tiles I&#8217;m drawing and posting here in my blog. This framework will be a group of classes for simplify and hide some complexities of common game development. Right now I wrote just a few of them.</p>
<p><strong>Use</strong></p>
<p>We create a tileset from the files.png file that way</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var tileset <span style="color: #339933;">=</span> Tileset <span style="color: #009900;">&#123;</span>
    cols<span style="color: #339933;">:</span> <span style="color: #cc66cc;">15</span> rows<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}tiles.png&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: center;"><img class="size-full wp-image-2110 aligncenter" title="tiles" src="http://silveiraneto.net/wp-content/uploads/2009/01/tiles.png" alt="tiles" width="285" height="237" /></p>
<p>Tileset are orthogonal, distributed into a grid of <em>cols</em> columns and <em>rows</em> rows. Each tile have dimensions <em>height</em> x <em>width</em>.</p>
<p>A Tileset is used into a Tilemap</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var bg <span style="color: #339933;">=</span> Tilemap <span style="color: #009900;">&#123;</span>
    set<span style="color: #339933;">:</span>tileset cols<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span> rows<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span>
    map<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That shows</p>
<p style="text-align: center;"><img class="size-full wp-image-2100 aligncenter" title="bg tilemap" src="http://silveiraneto.net/wp-content/uploads/2009/01/bg_tilemap.png" alt="bg tilemap" width="160" height="160" /></p>
<p>Each number in the map represents a tile in the tilemap. Number 0 means the first tile at the upper left corner, numbers keep growing from left to right columns, from top to bottom rows.</p>
<p>Another example</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var things <span style="color: #339933;">=</span> Tilemap <span style="color: #009900;">&#123;</span>
    set<span style="color: #339933;">:</span>tileset cols<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span> rows<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span>
    map<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">55</span>,<span style="color: #cc66cc;">56</span>,<span style="color: #cc66cc;">145</span>,<span style="color: #cc66cc;">145</span>,<span style="color: #cc66cc;">96</span>,<span style="color: #cc66cc;">71</span>,<span style="color: #cc66cc;">72</span>,<span style="color: #cc66cc;">61</span>,<span style="color: #cc66cc;">62</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">77</span>,<span style="color: #cc66cc;">78</span>,<span style="color: #cc66cc;">122</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">93</span>,<span style="color: #cc66cc;">94</span>,<span style="color: #cc66cc;">138</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: center;"><img class="size-full wp-image-2101 aligncenter" title="things tileset" src="http://silveiraneto.net/wp-content/uploads/2009/01/things_tileset.png" alt="things tileset" width="160" height="160" /></p>
<p>A tilemap can also contains more than one layer</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var room <span style="color: #339933;">=</span> Tilemap <span style="color: #009900;">&#123;</span>
    set<span style="color: #339933;">:</span>tileset cols<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span> rows<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span> layers<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span>
    map<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>,
        <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">55</span>,<span style="color: #cc66cc;">56</span>,<span style="color: #cc66cc;">145</span>,<span style="color: #cc66cc;">145</span>,<span style="color: #cc66cc;">96</span>,<span style="color: #cc66cc;">71</span>,<span style="color: #cc66cc;">72</span>,<span style="color: #cc66cc;">61</span>,<span style="color: #cc66cc;">62</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">77</span>,<span style="color: #cc66cc;">78</span>,<span style="color: #cc66cc;">122</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">93</span>,<span style="color: #cc66cc;">94</span>,<span style="color: #cc66cc;">138</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: center;"><img class="size-full wp-image-2102 aligncenter" title="tileroom" src="http://silveiraneto.net/wp-content/uploads/2009/01/tileroom.png" alt="tileroom" width="160" height="160" /></p>
<p><strong>Implementation</strong></p>
<p>The Tileset class basically stores a Image and a collection of Rectangle2D objects, for be used as viewports in <a href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.ImageView.html">ImageView</a> classes.</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;">javafx.scene.image.ImageView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.Image</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.geometry.Rectangle2D</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> Tileset <span style="color: #009900;">&#123;</span>
    public<span style="color: #339933;">-</span>init var      image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var      width<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var     height<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var       rows<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var       cols<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span>   var       tile<span style="color: #339933;">:</span> <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    init <span style="color: #009900;">&#123;</span>
        tile <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #006633;">rows</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #006633;">cols</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#123;</span>
                    minX<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> width, minY<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> height
                    height<span style="color: #339933;">:</span> width, width<span style="color: #339933;">:</span> height
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The Tilemap is a <a href="http://java.sun.com/javafx/1/docs/api/javafx.scene/javafx.scene.CustomNode.html">CustomNode</a> with a Group of ImageViews in a grid. The grid is mounted by iterating over the map as many layers was defined.</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: #000000; font-weight: bold;">class</span> Tilemap <span style="color: #000000; font-weight: bold;">extends</span> CustomNode <span style="color: #009900;">&#123;</span>
    public<span style="color: #339933;">-</span>init var   rows<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var   cols<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var    set<span style="color: #339933;">:</span> Tileset<span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var layers<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    public<span style="color: #339933;">-</span>init var    map<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> override function create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Node <span style="color: #009900;">&#123;</span>
        var tilesperlayer <span style="color: #339933;">=</span> rows <span style="color: #339933;">*</span> cols<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Group</span> <span style="color: #009900;">&#123;</span>
            content<span style="color: #339933;">:</span>
                <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>layer in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #006633;">layers</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #006633;">rows</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #006633;">cols</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            ImageView <span style="color: #009900;">&#123;</span>
                                image<span style="color: #339933;">:</span> set.<span style="color: #006633;">image</span> x<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> set.<span style="color: #006633;">width</span> y<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> set.<span style="color: #006633;">height</span>
                                viewport<span style="color: #339933;">:</span> set.<span style="color: #006633;">tile</span><span style="color: #009900;">&#91;</span>map<span style="color: #009900;">&#91;</span>tilesperlayer<span style="color: #339933;">*</span>layer <span style="color: #339933;">+</span> row<span style="color: #339933;">*</span>rows<span style="color: #339933;">+</span>col<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Next steps</strong></p>
<ul>
<li>Integrate to a map editor</li>
<li>Support some XML map format</li>
<li>Sprite classes for animation</li>
<li>Integrate those collision detection classes I posted before</li>
</ul>
<p><strong>Download</strong></p>
<ul>
<li>Source code and NetBeans project, <a title="download" href="http://silveiraneto.net/downloads/tileworld.tar.bz2">tileworld.tar.bz2</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/01/06/javafx-easy-use-of-tiles/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reading Twitter with JavaFX</title>
		<link>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/</link>
		<comments>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:56:55 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[microblogging]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2064</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/" title="Reading Twitter with JavaFX"></a>Twitter is a social network and micro-blogging service that allow you to create and read tweets, 140 characters text-based posts. It&#8217;s becoming a popular tool to keep in touch with your friends, coworkers, bloggers, etc. Here we&#8217;ll create a very &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/" title="Reading Twitter with JavaFX"></a><p style="text-align: center;"><img class="size-full wp-image-2073 aligncenter" title="twitter bird" src="http://silveiraneto.net/wp-content/uploads/2009/01/twitter-bird.gif" alt="twitter bird" width="250" height="184" /></p>
<p><a title="Twitter Micro Blogging Service" href="http://twitter.com">Twitter</a> is a social network and micro-blogging service that allow you to create and read tweets, 140 characters text-based posts. It&#8217;s becoming a popular tool to keep in touch with your friends, coworkers, bloggers, etc. Here we&#8217;ll create a very simple application that show us tweets related with a given word.</p>
<p>Twitter offers a very simple and powerfull <a href="http://apiwiki.twitter.com/">REST API</a> which supports <a rel="nofollow" href="http://en.wikipedia.org/wiki/XML"><span>XML</span></a>, <a rel="nofollow" href="http://en.wikipedia.org/wiki/Json"><span>JSON</span></a>, and the <a rel="nofollow" href="http://en.wikipedia.org/wiki/RSS"><span>RSS</span></a> and <a rel="nofollow" href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a> formats. As we are aiming just to read tweets we&#8217;ll use just the Search API.</p>
<p>We do that in three steps:</p>
<ol>
<li>Query Tweets</li>
<li>Parser the Atom result</li>
<li>Show tweets into a GUI</li>
</ol>
<p>Let&#8217;s see them in the order of dependence beetween them.</p>
<p><strong>Displaying a Tweet</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var gradient <span style="color: #339933;">=</span> LinearGradient <span style="color: #009900;">&#123;</span>
    startX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    startY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    endX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    endY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150.0</span>
    proportional<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
    stops<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">DARKGRAY</span> <span style="color: #009900;">&#125;</span>,
        Stop <span style="color: #009900;">&#123;</span> offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tweet <span style="color: #000000; font-weight: bold;">extends</span> CustomNode <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> var image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> var username<span style="color: #339933;">:</span> <span style="color: #003399;">String</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> var message<span style="color: #339933;">:</span> <span style="color: #003399;">String</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> override function create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Node <span style="color: #009900;">&#123;</span>
        var txt <span style="color: #339933;">=</span> Text <span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">65</span>  y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">35</span> wrappingWidth<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span>
            content<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{message}&quot;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Group</span> <span style="color: #009900;">&#123;</span>
            content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
                    width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">220</span> height<span style="color: #339933;">:</span> txt.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">height</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">40</span>
                    arcHeight<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span> arcWidth<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span> fill<span style="color: #339933;">:</span> gradient
                <span style="color: #009900;">&#125;</span>,
                ImageView <span style="color: #009900;">&#123;</span>
                    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">5</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> image<span style="color: #339933;">:</span> image
                <span style="color: #009900;">&#125;</span>,
                Text <span style="color: #009900;">&#123;</span>
                    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">65</span>  y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> content<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{username} said&quot;</span>
                <span style="color: #009900;">&#125;</span>,
                txt
            <span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For example, <a title="P4bl0's Tweet" href="http://twitter.com/p4bl0/statuses/1095717367">this tweet</a> would become:</p>
<p style="text-align: center;"><img class="size-full wp-image-2070 aligncenter" title="tweet example" src="http://silveiraneto.net/wp-content/uploads/2009/01/tweet_example.png" alt="tweet example" width="220" height="100" /></p>
<p><strong>Parsing ATOM result</strong></p>
<p>In <a title="XML Sandwich JavaFX " href="http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/">my last post about JavaFX</a> I showed how to parse XML documents (and make sandwiches) with JavaFX. Here we&#8217;ll use the Atom format, but use any other would be almost the same. Parsing XML or JSON documents with JavaFX is both very simple using the <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.data.pull/javafx.data.pull.PullParser.html">javafx.data.pull.PullParser</a> class.</p>
<p>A query output is a Atom XML document with several information. We are interested only in the fields that holds the avatar image, the message and the user name.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var tweets <span style="color: #339933;">=</span> VBox <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
def parser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
    var avatar<span style="color: #339933;">;</span>
    var firstname<span style="color: #339933;">;</span>
    var text<span style="color: #339933;">;</span>
    documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span><span style="color: #339933;">;</span>
&nbsp;
    onEvent<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><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>event.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">START_ELEMENT</span><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>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><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>event.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>QName<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;rel&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    avatar <span style="color: #339933;">=</span> event.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>QName<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">END_ELEMENT</span><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>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    text <span style="color: #339933;">=</span> event.<span style="color: #006633;">text</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span>and<span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">level</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                var names<span style="color: #339933;">:</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> event.<span style="color: #006633;">text</span>.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                firstname <span style="color: #339933;">=</span> names<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                insert Tweet <span style="color: #009900;">&#123;</span>
                        image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
                            url<span style="color: #339933;">:</span> avatar
                        <span style="color: #009900;">&#125;</span>
                        message<span style="color: #339933;">:</span> text
                        username<span style="color: #339933;">:</span> firstname
                    <span style="color: #009900;">&#125;</span> into tweets.<span style="color: #006633;">content</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: #009900;">&#125;</span></pre></div></div>

<p><strong>Querying Tweets</strong></p>
<p>We can get Atom results through url queries like that:</p>
<ul>
<li>Tweets containing the word Beatles <a href="http://search.twitter.com/search.atom?q=Beatles">http://search.twitter.com/search.atom?q=Beatles</a></li>
<li>Tweets from the user Silveira <a href="http://search.twitter.com/search.atom?q=from%3ASilveira">http://search.twitter.com/search.atom?q=from%3ASilveira</a></li>
<li>Tweets to the user Silveira <a href="http://search.twitter.com/search.atom?q=to%3ASilveira">http://search.twitter.com/search.atom?q=to%3ASilveira</a></li>
<li>Tweets containing the hashtag #CEJUG <a href="http://search.twitter.com/search.atom?q=to%23CEJUG">http://search.twitter.com/search.atom?q=to%23CEJUG</a></li>
</ul>
<p>Notice that queries should be URL encoded. We will use a additional parameters <strong>&amp;rpp=4</strong> to receive<strong> </strong>only 4 results per page. To know more about search queries read the <a title="Twitter Search API" href="http://apiwiki.twitter.com/Search+API+Documentation">Search API Documentation</a>. We get these results as  <a title="Java API InputStream" href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html">InputStreams</a> making asynchronous HTTP requests using the <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.io.http/javafx.io.http.HttpRequest.html">javafx.io.http.HttpRequest</a> class, which it&#8217;s perfect to invoke   RESTful Web Services.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">word <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Beatles&quot;</span><span style="color: #339933;">;</span>
var request <span style="color: #339933;">=</span> HttpRequest <span style="color: #009900;">&#123;</span>
    location<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://search.twitter.com/search.atom?q={word}&amp;amp;rpp=4&quot;</span><span style="color: #339933;">;</span>
    onInput<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">:</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">InputStream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parser.<span style="color: #006633;">input</span> <span style="color: #339933;">=</span> stream<span style="color: #339933;">;</span>
        parser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
request.<span style="color: #006633;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Conclusion</strong></p>
<p>Here is the application running for the word &#8220;House&#8221;.</p>
<p style="text-align: center;"><img class="size-full wp-image-2074 aligncenter" title="twitter with javafx" src="http://silveiraneto.net/wp-content/uploads/2009/01/twitter_with_javafx.png" alt="twitter with javafx" width="220" height="458" /></p>
<p>Is not a complete Twitter client, as it&#8217;s not intended to be, but can show you how to handle a simple asynchronous call and handle Twitter documents. There&#8217;s already a few beta JavaFX Twitter clients like <a title="Tweetbox at Google Code" href="http://code.google.com/p/tweetbox/">Tweetbox</a> and <a title="TwitterFX at Project Kenai" href="http://projectkenai.com/projects/twitterfx">Twitterfx</a> and certanly others will appears.</p>
<p><strong>Download</strong></p>
<p>Sources and Netbeans project, <a href="http://silveiraneto.net/downloads/fxtwitter.tar.bz2">fxtwitter.tar.bz2</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

