<?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>Blog Technologiczny ATENA &#187; RIA</title>
	<atom:link href="http://blog.atena.pl/category/ria/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.atena.pl</link>
	<description>JavaEE, AJAX, xHTML, RIA, JBoss</description>
	<lastBuildDate>Fri, 20 Jan 2012 11:18:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>JavaFX jako GUI do JBoss Seam? Nie ma problemu!</title>
		<link>http://blog.atena.pl/javafx-jako-gui-do-jboss-seam-nie-ma-problemu</link>
		<comments>http://blog.atena.pl/javafx-jako-gui-do-jboss-seam-nie-ma-problemu#comments</comments>
		<pubDate>Wed, 18 Aug 2010 08:20:33 +0000</pubDate>
		<dc:creator>Adam Andrzejewski</dc:creator>
				<category><![CDATA[Interfejs]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.atena.pl/?p=996</guid>
		<description><![CDATA[Jakiś czas temu napisałem artykuł opisujący wstępne założenia JavyFX. Wtedy też obiecałem, że gdy uda mi się uruchomić aplikację FXową na serwerze aplikacyjnym, podzielę się doświadczeniem. Właśnie nadszedł ten czas. Często można spotkać opinie, że JavaFX nie ma przyszłości, bo nie posiada żadnego wsparcia dla komunikacji z elementami biznesowymi. Kiedyś być może było to prawdą, [...]]]></description>
			<content:encoded><![CDATA[<p>Jakiś czas temu napisałem artykuł opisujący <a href="http://blog.atena.pl/wprawki-w-javafx">wstępne założenia JavyFX</a>. Wtedy też obiecałem, że gdy uda mi się uruchomić aplikację FXową na serwerze aplikacyjnym, podzielę się doświadczeniem. Właśnie nadszedł ten czas.</p>
<p><span id="more-996"></span></p>
<p>Często można spotkać opinie, że JavaFX nie ma przyszłości, bo nie posiada żadnego wsparcia dla komunikacji z elementami biznesowymi. Kiedyś być może było to prawdą, dziś naprzeciw takim oczekiwaniom wychodzi Flamingo. Jest to framework, który może stać się czymś w rodzaju „kleju” łączącego teoretycznie różne technologie, m.in. JavyFX i Seama.</p>
<p>Aby nie pozostawiać słów bez pokrycia, przygotuję projekt, który zaprezentuje możliwości Flamingo. Pokaże on jak łączyć JavaFX z Seamem. Na koniec wszystko wrzucimy na serwer aplikacji i uruchomimy z poziomu przeglądarki.</p>
<p>Zacznijmy od klasycznego projektu Seama. Wykorzystam tu Eclipse 3.5.2, Seama 2.2, JBossa 5.1 oraz JBoss Tools dla Eclipse, żeby szybko wygenerować działającą aplikację. Jeżeli jeszcze ich nie masz, czas się zaopatrzyć w te niezbędne narzędzia.</p>
<p>W Eclipse wybieramy New &#8211; &gt; Other -&gt; Seam -&gt; Seam Web Project</p>
<p><a href="http://blog.atena.pl/wp-content/uploads/2010/08/newseamapp.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/newseamapp.jpg" alt="" title="newseamapp" width="497" height="497" class="aligncenter size-full wp-image-997" /></a></p>
<p>Wypełniamy pola formularza:</p>
<ul>
<li>nazwa projektu: SeamApp</li>
<li>Target runtime: JBoss 5.1 Runtime</li>
<li>Dynamic Web Module Vesion: 2.5</li>
<li>Target Server: JBoss 5.1 Runtime Server</li>
<li>Configuration: Dynamic web project with JBoss Seam 2.2.0</li>
</ul>
<p><a href="http://blog.atena.pl/wp-content/uploads/2010/08/seamwiz1.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/seamwiz1.jpg" alt="" title="seamwiz1" width="480" height="576" class="aligncenter size-full wp-image-998" /></a></p>
<p>Najprawdopodobniej nazwy docelowego runtime’u i serwera będą inne &#8211; w zależności od tego co sobie skonfigurujemy. Najważniejsze, by wybrać JBoss 5.1 (Seam 2.2. teoretycznie działa też na wcześniejszych wersjach).</p>
<p>Przez kilka kolejnych ekranów konfiguratora możemy przeskoczyć z domyślnymi ustawieniami. Dotrzemy ostatecznie do ekranu z wyborem bazy danych i sposobu deploymentu aplikacji. Ponieważ przykłady mają być proste, wybieramy pakowanie do war i bazę HSQLową – lub dowolną inną, nie będziemy korzystać tutaj z tego elementu.<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/08/seamwiz2.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/seamwiz2.jpg" alt="" title="seamwiz2" width="479" height="575" class="aligncenter size-full wp-image-999" /></a></p>
<p>Możemy zmienić jeszcze domyślne pakiety, ale nie jest to konieczne.</p>
<p>Wygenerowana aplikacja jest gotowa do użycia i deploymentu – zawiera wszystkie niezbędne elementy do uruchomienia, przykładowe strony oraz klasę Authenticator służącą do autentykacji użytkownika w systemie. Dla pewności możemy uruchomić aplikację by upewnić się, że wszystko poszło ok.</p>
<p>Aby móc podpiąć się do aplikacji za pomocą JavaFX, musimy dodać do niej kilka niezbędnych elementów. Są to biblioteki Flamingo (linki do wszystkich materiałów znajdują się na końcu artykułu):</p>
<ul>
<li>amf-serializer.jar</li>
<li>flamingo-service.jar</li>
<li>flamingo-services-common.jar</li>
<li>hessian.jar</li>
<li>scannotation.jar</li>
</ul>
<p>Umieszczamy je bezpośrednio w katalogu lib aplikacji. W skład Flamingo wchodzi jeszcze parę bibliotek, ale do podstawowego przykładu wystarczą te. Aby móc wywoływać komponenty Seam musimy jeszcze dodać do pliku web.xml wpis definiujący servlet, który będzie odpowiadał za komunikację JavaFX z Seamem</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;servlet&gt;<br />
&nbsp; &nbsp; &lt;servlet-name&gt;Hessian Remote Servlet&lt;/servlet-name&gt;<br />
&nbsp; &nbsp; &lt;servlet-class&gt;com.exadel.flamingo.service.seam.HessianToSeamServlet&lt;/servlet-class&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet-mapping&gt;<br />
&nbsp; &nbsp; &lt;servlet-name&gt;Hessian Remote Servlet&lt;/servlet-name&gt;<br />
&nbsp; &nbsp; &lt;url-pattern&gt;/flamingo/hessian/*&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;</div></td></tr></tbody></table></div>
<p>Teraz już możemy dostać się do dowolnego komponentu Seam w naszej aplikacji za pomocą Flamingo. Przykładowa aplikacja posiada tylko jeden komponent (autentykator), więc wykorzystajmy go, aby nie komplikować całości. Do klasy Authenticator.java dodajmy metodę</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> hello<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Hello &quot;</span> <span style="color: #339933;">+</span> name <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;!&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Pozostanie ona naszą metodą, którą będziemy wywoływać z poziomu aplikacji FX-owej.</p>
<p>Czas na stworzenie klienta tej jakże wyrafinowanej metody. <img src='http://blog.atena.pl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>W Eclipse tworzymy nowy projekt, w którym znajdą się zarówno klasy Java jak i JavaFX. Polecam by zainstalować sobie wytczkę  <a href="http://exadel.org/javafxplugin">Exadel JavaFX Eclipse plugin</a>. Ułatwia ona nieco tworzenie projektów FX-owych w Eclipse. Do tej części wymagane jest też posiadanie JavaFX 1.3 SDK. Jeżeli jeszcze go nie masz – czas zainstalować.</p>
<p>Wybieramy New -&gt; Other -&gt; JavaFX -&gt; JavaFX Project<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/08/newfxapp.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/newfxapp.jpg" alt="" title="newfxapp" width="497" height="496" class="aligncenter size-full wp-image-1000" /></a></p>
<p>Na kolejnych ekranach wizarda wybieramy nazwę projektu (FxClient), wersję SDK JavyFX, oraz JDK do wykorzystania w projekcie. Po &#8222;doklikaniu&#8221; do końca wizarda zostanie utworzony projekt ze wszystkimi niezbędnymi bibliotekami do pisania uruchamiania aplikacji FXowej.</p>
<p>Aby móc skorzystać z mechanizmów Seamowych, musimy dodać jeszcze trzy biblioteki. Tworzymy katalog lib i wrzucamy do niego:</p>
<ul>
<li>jboss-seam.jar (z instalacji seama)</li>
<li>jboss-seam-remoting.jar (jw.)</li>
<li>hessian.jar (ta sama wersja co w aplikacji Seamowej)</li>
</ul>
<p>Teraz musimy dodać interfejs, który będzie bramką do naszej usługi seamowej. W idealnym świecie pewnie byłby on zawarty w dostarczonym z zewnątrz jarze z API, ale upraszczamy wszystko jak możemy.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.atena.client.seam.api</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> HelloWorld <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> hello<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Potrzebna będzie też fabryka tej usługi, dodajmy więc i ją:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.atena.client.java</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.MalformedURLException</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.caucho.hessian.client.HessianProxyFactory</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">pl.atena.client.seam.api.HelloWorld</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorldClient <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> HelloWorldClient CLIENT<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _url<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HelloWorld _service<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HelloWorldClient<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _url <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> setServerUrl<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CLIENT <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HelloWorldClient<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HelloWorld getService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_service <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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HessianProxyFactory factory <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HessianProxyFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//(1)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _service <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HelloWorld<span style="color: #009900;">&#41;</span> factory.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>HelloWorld.<span style="color: #000000; font-weight: bold;">class</span>, _url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//(2)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amalformedurlexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MalformedURLException</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _service<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> hello<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> getService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">hello</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Krótki komentarz do powyższego:</p>
<p>(1)   – Tworzymy nową instancję fabryki połączeń. Komunikacja za pomocą JavaFX i Seam odbywa się po protokole Hessian.</p>
<p>(2)   – Pobieramy instancję usługi HelloWorld na podstawie adresu URL zasobu. Parametr ten ustawimy już bezpośrednio w skrypcie FX i tam opiszę jego wygląd.</p>
<p>Pozostał nam jeszcze skrypt FX który skorzysta z usługi Seamowej. Utwórzmy go zatem:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*<br />
<br />
*MainFrame.fx<br />
<br />
*<br />
<br />
*Created on sie 12, 2010, 08:09:02 AM<br />
<br />
*/</span><br />
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.atena.client.fx</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.text.Text</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.text.Font</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.layout.HBox</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.Color</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.text.TextOrigin</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingButton</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.layout.VBox</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.control.TextBox</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">pl.atena.client.java.HelloWorldClient</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> Hello<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//(1)</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> var name<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> var str<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #339933;">;</span> &nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><br />
<br />
var helloModel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
HelloWorldClient.<span style="color: #006633;">setServerUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:8080/SeamApp/flamingo/hessian/authenticator&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//(2)</span><br />
<br />
var helloText<span style="color: #339933;">:</span> TextBox <span style="color: #339933;">=</span> TextBox <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; text<span style="color: #339933;">:</span> bind helloModel.<span style="color: #006633;">name</span> with inverse <span style="color: #666666; font-style: italic;">//(3)</span><br />
&nbsp; &nbsp; columns<span style="color: #339933;">:</span> <span style="color: #cc66cc;">7</span><br />
&nbsp; &nbsp; selectOnFocus<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">true</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
var helloLabel <span style="color: #339933;">=</span> Text<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; y<span style="color: #339933;">:</span><span style="color: #cc66cc;">8</span><br />
&nbsp; &nbsp; font<span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afont+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Font</span></a> <span style="color: #009900;">&#123;</span> name<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;sansserif&quot;</span>, size<span style="color: #339933;">:</span> <span style="color: #cc66cc;">12</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; fill<span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acolor+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Color</span></a>.<span style="color: #006633;">BLACK</span><br />
&nbsp; &nbsp; content<span style="color: #339933;">:</span> bind <span style="color: #0000ff;">&quot;Server says: {helloModel.str}&quot;</span><br />
&nbsp; &nbsp; textOrigin<span style="color: #339933;">:</span> TextOrigin.<span style="color: #006633;">TOP</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
var helloButton <span style="color: #339933;">=</span> SwingButton &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;Say Hello!&quot;</span><br />
&nbsp; &nbsp; action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; helloModel.<span style="color: #006633;">str</span> <span style="color: #339933;">=</span> HelloWorldClient.<span style="color: #006633;">CLIENT</span>.<span style="color: #006633;">hello</span><span style="color: #009900;">&#40;</span>helloModel.<span style="color: #006633;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//(4)</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
Stage <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//(5)</span><br />
&nbsp; &nbsp; title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Helloworld Sample&quot;</span><br />
&nbsp; &nbsp; width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span><br />
&nbsp; &nbsp; height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span><br />
&nbsp; &nbsp; scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> VBox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translateX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translateY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spacing<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HBox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> helloText<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spacing<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HBox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> helloButton<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spacing<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HBox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> helloLabel<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spacing<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>(1)    – Tworzymy miniklasę, w której będziemy trzymać imię do powitania, oraz odpowiedź z komponentu Seam.<br />
(2)    – Ustawiamy adres do komponentu Seam do którego chcemy się odwołać. Generalnie powinien mieć on postać http://adres_serwera/kontekst_aplikacji/flamingo/hessian/nazwa_komponentu_seam, przy czym /flamingo/hessian to ścieżka dla servletu Flamingo którą wpisaliśmy w web.xml aplikacji seamowej.<br />
(3)    – Wiążemy zawartość pola tekstowego z jedną ze zmiennych naszej miniklasy.<br />
(4)    – Podpinamy wywołanie usługi pod kliknięcie na przycisk.<br />
(5)    – Tworzymy scenę, na której umieszczone zostaną nasze elementy graficzne.</p>
<p>W tym momencie (jeżeli mamy uruchomioną aplikację seamową oczywiście) możemy już uruchomić aplikację FXową i sprawdzić czy wszystko się udało.<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/08/run.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/run.jpg" alt="" title="run" width="200" height="147" class="aligncenter size-full wp-image-1001" /></a><br />
Jak widać, udało nam się wywołać komponent Seam z aplikacji desktopowej.</p>
<p>Czas podnieść sobie nieco poprzeczkę, i zrobić to samo z aplikacji webowej.</p>
<p>Tu też przydatny jest plugin do eclipse, gdyż może on za nas załatwić mozolną walkę z kompilacją do pliku jar wraz z wymaganymi bibliotekami (javafxpackager z linii poleceń też może to zrobić, ale wówczas trzeba się trochę napisać…).</p>
<p>Aby przygotować plik jar odpowiedni do wykorzystania na serwerze aplikacji wystarczy kliknąć na naszym skrypcie prawym przyciskiem myszy i wybierać Run as -&gt; JavaFX Application (applet)<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/08/runasapplet.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/runasapplet.jpg" alt="" title="runasapplet" width="983" height="630" class="aligncenter size-full wp-image-1002" /></a><br />
W folderze dist projektu zostaną utworzone następujące elementy</p>
<ul>
<li>plik jar ze skompilowanym skryptem FX</li>
<li>pliki jnlp, umożliwiające uruchamianie aplikacji przez Java Web Start</li>
<li>strona html, w treści której umieszczony został aplet ze skryptem FX</li>
</ul>
<p>Wszystko to przenosimy do katalogu WebContent naszej aplikacji Seamowej, zmieniamy nazwę wygenerowanego przez kompilator pliku html na index.html i robimy redeploy całej aplikacji. Teraz pod domyślnym adresem aplikacji seamowej powinniśmy otrzymać działający skrypt JavyFX<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/08/inbrowser.jpg"><img src="http://blog.atena.pl/wp-content/uploads/2010/08/inbrowser.jpg" alt="" title="inbrowser" width="421" height="297" class="aligncenter size-full wp-image-1003" /></a><br />
Prawda, że to proste?</p>
<p>Na koniec jeszcze jedna ciekawostka. Jeżeli zmodyfikujemy plik index.html i dodamy do definicji apletu parametr draggable, będziemy mogli dosłownie wyciągnąć aplet na pulpit (trzymając klawisz alt oraz lewy przycisk myszy) i korzystać z niego nawet po zamknięciu przeglądarki.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;<br />
&lt;title&gt;MainFrame&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;MainFrame&lt;/h1&gt;<br />
&lt;script src=&quot;http://dl.javafx.com/1.3/dtfx.js&quot;&gt;&lt;/script&gt;<br />
&lt;script&gt;<br />
&nbsp; &nbsp; javafx(<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; archive: &quot;MainFrame.jar&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; draggable: true,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 400,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 400,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; code: &quot;pl.atena.client.fx.MainFrame&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extPackages: &quot;javafx.ext.swing&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: &quot;MainFrame&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; );<br />
&lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div></td></tr></tbody></table></div>
<p>Podsumowując, Flamingo pozwala nam łatwo zintegrować aplikację FXową z aplikacją Seamową. Dzięki niemu możemy korzystać z komponentów Seama zarówno w aplikacji desktopowej, jak i wykorzystać JavaFX do stworzenia interfejsu użytkownika bezpośrednio w aplikacji seamowej. Aplikację przygotowaną w ten sposób bez problemu można umieścić na serwerze, a także udostępnić wersję desktopową przez jnlp. JavaFX nie zabrania wykorzystania innych elementów na stronie, może współistnieć z innymi elementami i bibliotekami. Czas więc zakasać rękawy i stworzyć prawdziwe RIA.</p>
<p>Zasoby i bibliografia</p>
<ul>
<li><a href="http://exadel.org/flamingo">Framework Flamingo</a></li>
<li><a href="http://exadel.org/javafxplugin">Exadel JavaFX Eclipse Plugin</a></li>
<li><a href="http://mkblog.exadel.com/2010/07/enterprise-javafx-with-seam-and-flamingo-complete-edition/">Maxa Blog</a> (wiele pomocnych artykułów na temat łączenia Seama z JavaFX, również bardziej zaawansowanych – polecam!)</li>
<li><a href='http://blog.atena.pl/wp-content/uploads/2010/08/jars.zip'>wymagane pliki jar frameworku flamingo</a>
<li><a href='http://blog.atena.pl/wp-content/uploads/2010/08/FxClient.zip'>FxClient</a></li>
<li><a href='http://blog.atena.pl/wp-content/uploads/2010/08/SeamApp.zip'>Seam App wersja final (z dodanym apletem klienta)</a></li>
<li><a href="http://javafx.com/downloads/all.jsp">JavaFX SDK</a> jeżeli mamy już JDK 1.6.20</li>
<li><a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk-javafx-jsp-142924.html">JDK + JavaFX SDK</a> jeżeli nie mamy jeszcze JDK w wersji 1.6.20</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.atena.pl/javafx-jako-gui-do-jboss-seam-nie-ma-problemu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wprawki w JavaFX</title>
		<link>http://blog.atena.pl/wprawki-w-javafx</link>
		<comments>http://blog.atena.pl/wprawki-w-javafx#comments</comments>
		<pubDate>Wed, 21 Apr 2010 08:42:57 +0000</pubDate>
		<dc:creator>Adam Andrzejewski</dc:creator>
				<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.atena.pl/?p=937</guid>
		<description><![CDATA[Rośnie popularność aplikacji RIA. Powstaje coraz więcej narzędzi i języków do tworzenia takich aplikacji. W tym artykule postaram się przedstawić podstawy JavaFX &#8211; języka skryptowego ze stajni SUNa. JavaFX na początku zniechęcała mnie od siebie reklamując się jako język skryptowy &#8211; miałem zbyt dużo złych skojarzeń z Javasciptem, a konkretnie z brakiem statycznego typowania argumentów. [...]]]></description>
			<content:encoded><![CDATA[<p>Rośnie popularność aplikacji RIA. Powstaje coraz więcej narzędzi i języków do tworzenia takich aplikacji. W tym artykule postaram się przedstawić podstawy JavaFX &#8211; języka skryptowego ze stajni SUNa.</p>
<p><span id="more-937"></span>JavaFX na początku zniechęcała mnie od siebie reklamując się jako język skryptowy &#8211; miałem zbyt dużo złych skojarzeń z Javasciptem, a konkretnie z brakiem statycznego typowania argumentów. Jednak już po lekturze paru artykułów i pierwszej prostej aplikacji okazuje się, że nie jest tak źle &#8211; powiedziałbym nawet, że jest całkiem nieźle.</p>
<p>Jako narzędzie do developmentu wybrałem <a href="http://javafx.com/downloads/" target="_blank">NetBeans IDE for JavaFX</a> &#8211; wtyczka do eclipse jest również dostępna, jednak dopiero dla wersji 3.5.</p>
<p>Przejdźmy do konkretów. Stwórzmy prosty kalkulator by poznać semantykę języka. Uruchamiamy NetBeans, i wybieramy New Project</p>
<p><a href="http://blog.atena.pl/wp-content/uploads/2010/03/createproject.png"><img class="aligncenter size-full wp-image-938" title="createproject" src="http://blog.atena.pl/wp-content/uploads/2010/03/createproject.png" alt="" width="729" height="496" /></a></p>
<p>Z kategorii wybieramy JavaFX, klikamy next</p>
<p><a href="http://blog.atena.pl/wp-content/uploads/2010/03/createproject2.png"><img class="aligncenter size-full wp-image-939" title="createproject2" src="http://blog.atena.pl/wp-content/uploads/2010/03/createproject2.png" alt="" width="730" height="452" /></a>Uzupełniamy nazwę projektu, zaznaczamy &#8222;Empty Project&#8221;, &#8222;Set as Main Project&#8221; oraz odznaczamy &#8222;Create Main File&#8221;. Klikamy Finish &#8211; NetBeans wygeneruje dla nas projekt kalkulatora.</p>
<p>Po utworzeniu projektu dodajemy naszą klasę &#8222;Calculator&#8221;. Klikamy prawym na projekcie, wybieramy &#8222;New&#8221; -&gt; &#8222;Empty JavaFX File&#8221; i uzupełniamy nazwę klasy. Opcjonalnie można uzupełnić nazwę pakietu, ale w tym przykładzie nie jest to konieczne. Następnie uzupełniamy ciało klasy &#8211; aby było to bardziej czytelne. pozwolę sobie nieco skrócić opis. Cały projekt można pobrać <a href="http://blog.atena.pl/wp-content/uploads/2010/03/Calculator.zip">tutaj</a></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.control.TextBox</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.control.Button</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.input.MouseEvent</span><span style="color: #339933;">;</span><br />
<br />
var currResult<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
var firstElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var secondElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var funcToRun<span style="color: #339933;">:</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
var funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
Stage <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX quick calculator!&quot;</span><br />
&nbsp; &nbsp; scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">130</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;......<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">//Content</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//Scene</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Pierwsze co rzuca się w oczy to</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span></div></td></tr></tbody></table></div>
<p>, który znany jest wszystkim programistom Javy i nie tylko. Okazuje się, że JavaFX mimo że jest językiem skryptowym jest kompilowana do bytecode maszyny wirtualnej i tam uruchamiana. Dalej mamy definicje zmiennych, gdzie obserwujemy ciekawą właściwość JavyFX, a mianowicie możliwość (ale nie konieczność!) określenia typu danych jakie reprezentuje dana zmienna. Kompilator sam domyślnie jest w stanie nadać typ na podstawie pierwszej przypisanej zmiennej. A zatem obie konstrukcje -</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
var funcDefined<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aboolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Boolean</span></a> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>- są jak najbardziej poprawne i akceptowane przez kompilator. JavaFX udostępnia sporo wbudowanych typów danych jednak na potrzeby kalkulatora wystarczy nam Boolean, Number (liczby zmiennoprzecinkowe) i function(). Function() nie jest w ścisłym znaczeniu typem danych, ale pozwala zdefiniować zmienną, której użyjemy w dość ciekawy sposób później.</p>
<p>Stage definiuje nam nasze &#8222;okno robocze&#8221;, czyli obszar w którym będziemy dodawać i wyświetlać nasze komponenty. Scena to element właściwy w którym pojawia się zawartość.</p>
<p>Struktura elementów w JavaFX nieodzownie kojarzy się mi z DOM &#8211; chodzi o rozrastające się ku dołowi drzewo. W każdym elemencie możemy definiować kolejne elementy coraz bardziej rozgałęziając drzewo. Dodajmy parę gałęzi do sceny &#8211; niech to będzie pole tekstowe, w którym będą pojawiać się wyniki oraz przyciski funkcyjne kalkulatora.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var currResult<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
var firstElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var secondElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var funcToRun<span style="color: #339933;">:</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
var funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
Stage <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX quick calculator!&quot;</span><br />
&nbsp; &nbsp; scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">130</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span> bind currResult.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;editable<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;…<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseClicked<span style="color: #339933;">:</span>function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>funcDefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; funcToRun<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcToRun<span style="color: #339933;">=</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currResult<span style="color: #339933;">=</span>firstElem<span style="color: #339933;">+</span>secondElem<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstElem<span style="color: #339933;">=</span>currResult<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secondElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>, &nbsp;<span style="color: #666666; font-style: italic;">//... kolejne przyciski dla -, *, /, =</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">//Content</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//Scene</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Każdy element jak widać jest dość mocno zbliżony do siebie w definicji &#8211; posiada koordynaty położenia, dane dotyczące wymiaru i tekst jaki ma się pojawiać.<br />
Warte zauważenia jest słówko</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">bind</div></td></tr></tbody></table></div>
<p>- określna ono wiązanie pomiędzy naszą zmienną currResult a polem tekstowym TextBox. Wykorzystanie <i>bind</i><br />
pozwala nam nie martwić się o aktualizowanie pola tekstowego gdy zmieni się wynik przechowywany w zmiennej currResult &#8211; <i>bind</i><br />
sprawia, że zmiana currResult jest automatycznie propagowana do elementu</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">text</div></td></tr></tbody></table></div>
<p>TextBoxa. Drugą istotną rzeczą jest element</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">onMousceClicked</div></td></tr></tbody></table></div>
<p>JavaFX pozwala definiować funkcje listenerów na dane zdarzenia (tu kliknięcie myszką na przycisk) w prosty sposób. W naszym przykładzie nadpisujemy zdefiniowaną wcześniej zmienną:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">funcToRun</div></td></tr></tbody></table></div>
<p>przez podanie nowego ciała metody. Zostaje dodać nam przyciski cyfr, przycisk CE i „=”,  by kalkulator mógł zacząć działać</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var currResult<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
var firstElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var secondElem<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumber+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Number</span></a><span style="color: #339933;">;</span><br />
var funcToRun<span style="color: #339933;">:</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
var funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
Stage <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX quick calculator!&quot;</span><br />
&nbsp; &nbsp; scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">130</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBox<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span> bind currResult.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;editable<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseClicked<span style="color: #339933;">:</span>function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>not funcDefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstElem<span style="color: #339933;">=</span>firstElem<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;currResult<span style="color: #339933;">=</span>firstElem<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;secondElem<span style="color: #339933;">=</span>secondElem<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<span style="color: #666666; font-style: italic;">//... kolejne przyciski dla pozostałych cyfr</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseClicked<span style="color: #339933;">:</span>function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>funcDefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; funcToRun<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcToRun<span style="color: #339933;">=</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currResult<span style="color: #339933;">=</span>firstElem<span style="color: #339933;">+</span>secondElem<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstElem<span style="color: #339933;">=</span>currResult<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secondElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span>, &nbsp;<span style="color: #666666; font-style: italic;">//... kolejne przyciski dla -, *, /</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">125</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;CE&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseClicked<span style="color: #339933;">:</span>function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcToRun<span style="color: #339933;">=</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;currResult <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;secondElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutX<span style="color: #339933;">:</span><span style="color: #cc66cc;">67</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layoutY<span style="color: #339933;">:</span><span style="color: #cc66cc;">125</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span style="color: #339933;">:</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span style="color: #339933;">:</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseClicked<span style="color: #339933;">:</span>function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>funcDefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; funcToRun<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcToRun<span style="color: #339933;">=</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcDefined <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;secondElem <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">//Content</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//Scene</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Jak widać struktura przycisków z cyframi niczym nie różni się od przycisków funkcyjnych. W ramach eventu onMouseClicked ustawiamy parametry i ewentualnie wywołujemy funkcję zdefiniowaną w przycisku funkcyjnym. I to już cały kod &#8211; wystarczy uruchomić projekt klikając F6 w IDE. W efekcie dostajemy okienko w którym możemy przetestować nasz kalkulator<br />
<a href="http://blog.atena.pl/wp-content/uploads/2010/03/calculator1.png"><img class="aligncenter size-full wp-image-946" title="calculator" src="http://blog.atena.pl/wp-content/uploads/2010/03/calculator1.png" alt="" width="141" height="176" /></a></p>
<p>To tyle jeżeli chodzi o pierwsze wprawki w JavaFX.</p>
<p>Podsumowując &#8211; czego dziś dowiedziałem się o JavaFX?<br />
•	Jest językiem skryptowym który umożliwia, ale nie wymusza określanie typu zmiennych<br />
•	Struktura budowanego widoku opiera się na drzewie<br />
•	Najważniejsze elementy tego drzewa to Stage i Scene<br />
•	Pozwala tworzyć wiązania między zmiennymi a elementami GUI<br />
•	Umożliwia proste zarządzanie zdarzeniami (zwane eventami)<br />
Język rozwija się dynamicznie – kolejne jego wersje wzbogacane są nie tylko o nowe komponenty lecz także o konstrukcje składniowe języka, a wszystko po to, by maksymalnie uprościć pisanie aplikacji z efektownym GUI.<br />
Biorąc pod uwagę możliwość uruchamiania aplikacji JavaFX zarówno jako aplikacji desktopowych, serwerowych oraz mobilnych wróżę temu językowi dość jasną przyszłość. </p>
<p>Pozostaje zgłębiać dostępne klasy i mechanizmy, a gdy uda mi się stworzyć prostą aplikację web i uruchomić ją na serwerze nie omieszkam podzielić się tym doświadczeniem</p>
<p>Materiały dodatkowe:</p>
<ul>
<li><a href="http://java.sun.com/javafx/1/tutorials/core/getStarted/">JavaFX tutorial</a></li>
<li><a href="http://blog.atena.pl/wp-content/uploads/2010/03/Calculator.zip">Calculator Project</a></li>
<li><a href="http://javafx.com/downloads/" target="_blank">NetBeans IDE for  JavaFX</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.atena.pl/wprawki-w-javafx/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wstęp do GWT</title>
		<link>http://blog.atena.pl/wstep-do-gwt</link>
		<comments>http://blog.atena.pl/wstep-do-gwt#comments</comments>
		<pubDate>Thu, 15 Oct 2009 12:11:38 +0000</pubDate>
		<dc:creator>Adam Andrzejewski</dc:creator>
				<category><![CDATA[Interfejs]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.atena.pl/?p=493</guid>
		<description><![CDATA[Google Web Toolkit (GWT) to framework dostarczony przez Google do budowania aplikacji opartych na języku Java z bogatym front-endem AJAXowym. GWT pozwala pisać aplikacje w Javie dostarczając zestaw bibliotek do tworzenia dialogów, przycisków, formularzy itp. Następnie kompiluje je i optymalizuje tworząc JavaScript, który powinien działać prawidłowo na wszystkich najpopularniejszych przeglądarkach. Kompilacja obejmuje statyczne sprawdzanie typów, wyrzucanie niepotrzebnych parametrów z [...]]]></description>
			<content:encoded><![CDATA[<p>Google Web Toolkit (GWT) to framework dostarczony przez Google do  budowania aplikacji opartych na języku Java z bogatym front-endem AJAXowym. GWT  pozwala pisać aplikacje w Javie dostarczając zestaw bibliotek do tworzenia  dialogów, przycisków, formularzy itp. Następnie kompiluje je i  optymalizuje tworząc JavaScript, który powinien działać prawidłowo na wszystkich  najpopularniejszych przeglądarkach. Kompilacja obejmuje statyczne sprawdzanie  typów, wyrzucanie niepotrzebnych parametrów z metod, pól z klas, in-linowaniem  metod &#8211; wszystko by maksymalnie przyśpieszyć działanie.</p>
<p><span id="more-493"></span></p>
<p>Instalacja  GWT jest nadzwyczaj prosta. Wystarczy pobrać zzipowaną wersję z  <a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/download.html">http://code.google.com/intl/pl/webtoolkit/download.html</a> i  rozpakować w dowolne miejsce. GWT integruje się z eclipse 3.3 i 3.4 poprzez  pluginy (instalacja opisana na <a rel="nofollow" href="http://code.google.com/intl/pl/eclipse/docs/download.html">http://code.google.com/intl/pl/eclipse/docs/download.html</a>).</p>
<p>Po poprawnej instalacji wtyczki na pasku narzędziowym eclipse dostajemy trzy  nowe ikony   <img class="alignnone size-full wp-image-494" src="http://blog.atena.pl/wp-content/uploads/2009/07/gtwicons.jpg" alt="gtwicons" width="96" height="40" />. Pierwsza z nich tworzy nam nowy projekt GWT, druga kompiluje  go, trzecia wreszcie służy do deplyowania projektów Google App Engine.</p>
<p>Podczas pierwszego projektu musimy wskazać miejsce, w którym jest rozpakowane  GWT. Domyślnie stworzenie nowego projektu generuje przykładową aplikację.  Dodatkowo z menu kontekstowego Run As w projekcie możemy wybrać Web Application  i automatycznie ona uruchomiona w dostarczonej z biblioteką przeglądarce, w tzw &#8222;hosted mode&#8221;</p>
<p style="text-align: center;"><img class="size-full wp-image-495 aligncenter" src="http://blog.atena.pl/wp-content/uploads/2009/07/runaswebapp.jpg" alt="runaswebapp" width="549" height="425" /></p>
<p style="text-align: center;"><img class="aligncenter size-large wp-image-498" src="http://blog.atena.pl/wp-content/uploads/2009/07/webappbrowser-1024x656.jpg" alt="webappbrowser" width="664" height="425" /></p>
<p style="text-align: center;">
<p style="text-align: left;">Główne zalety GWT:</p>
<ul>
<li>edit &#8211; refresh &#8211; view &#8211; używając &#8222;hosted browser&#8221; do testowania aplikacji,  zmiany w kodzie javy nie wymagają dodatkowej kompilacji czy restartu, wystarczy  odświeżyć stronę i zmiany będą widoczne;</li>
<li>możliwość debugowania aplikacji za pomocą eclipsowego debugera;</li>
<li>wsparcie dla JSON, XML,  a także możliwość łatwego wywoływania procedur po stronie  serwera (serializowanie i deserializowanie obiektów, zachowanie jak przy RMI);</li>
<li>wsparcie dla JavaScript Native Interface przez co możliwe jest samodzielne dodawanie  kodu JavaScript do tworzonej aplikacji;</li>
<li>wsparcie dla przycisku &#8222;wstecz&#8221; dla przeglądarek, przez modyfikację historii  przeglądanych stron;</li>
<li>współpraca z JUnit, JProfiler;</li>
<li>praca w 2 trybach &#8211; hosted mode (jw z eclipse, po wykonaniu ant hosted, itp  bez całkowitej zamiany kodu na javascript) i web mode (zamiana kodu na  javascript);</li>
<li>pisanie interfejsów użytkownika analogicznie jak w Swing;</li>
<li>możliwość rozbudowania o własne moduły lub inne opensourcowe pluginy (np. wspierające  drag and drop w aplikacji);</li>
<li>szerokie wsparcie dla internacjonalizacji;</li>
<li>możliwość własnego ostylowania elementów za pomocą CSS.</li>
</ul>
<p>GWT posiada kilkanaście gotowych elementów do budowy dynamicznych efektownych interfejsów, np:</p>
<ul>
<li>panele (DecoratorPanel, VerticalPanel, HorizontalPanel, FlowPanel,  AbsolutePanel, DockPanel)</li>
<li>widgety (CheckBox, RadioButton, Button, CustomButton, FileUpload, DatePicker, Hyperlink)</li>
<li>listy i menu (ListBox, SelectBox, Tree, MenuBar)</li>
<li>inputy (TextBox, RichTextArea)</li>
<li>okna (DialogBox, DecoratedPopupPanel)</li>
<li>tabele (FlexTable, Grid)</li>
<li>animacje (Animation)</li>
</ul>
<p>Możliwości frameworku można obejrzeć na następujących stronach</p>
<ul>
<li><a href="http://gwt.google.com/samples/Mail/Mail.html">http://gwt.google.com/samples/Mail/Mail.html</a></li>
<li><a href="http://gwt.google.com/samples/DynaTable/DynaTable.html">http://gwt.google.com/samples/DynaTable/DynaTable.html</a></li>
<li><a href="http://gwt.google.com/samples/Showcase/Showcase.html">http://gwt.google.com/samples/Showcase/Showcase.html</a></li>
</ul>
<p>Dodatkowo istnieje biblioteka GWT-ext która dostarcza zdecydowanie więcej gotowych komponentów. Demo tej biblioteki można zobaczyć na <a rel="nofollow" href="http://www.gwt-ext.com/demo/">http://www.gwt-ext.com/demo/</a></p>
<p>GWT docelowo jest zamieniane całkowicie na JavaScript, dlatego choć pisze się go w Javie, są pewne istotne ograniczenia w wykorzystaniu standardowych bibliotek:</p>
<ul>
<li>JavaScript obsługuje tylko 64bitową wersję liczby zmienno przecinkowej,  dlatego też wszystkie typy numeryczne, jak byte, short, int, są w trybie web  zamieniane na double, a to z kolei pozwala na zwiększenie dozwolonego zakresu liczbowego; typ  long jest emulowany na podstawie dwóch 32bitowych intów, co może spowodować  spadek wydajności poprzez konieczność emulacji;</li>
<li>try, catch, finally działają poprawnie, jednak Throwable.getStackTrace() nie  jest dostępne;</li>
<li>niektóre wyjątki nie występują w trybie web, np. NullPointerException,  StackOverflowException czy OutOfMemoryException;  zamiast nich rzucany jest  wyjątek JavaScriptException; takie zachowanie wynika z niemożności  zmapowania odpowiedniego wyjątku JavaScriptowego na wyjątek Javy;</li>
<li>multithreading &#8211; interpretery JavaScript są jednowątkowe, a zatem, choć GWT  akceptuje &#8222;synchronized&#8221; to tak naprawdę nie robi ono nic specjalnego; inne  wsparcie wielowątkowości jak wait() notify() nie jest dostępne;</li>
<li>wykorzystywanie mechanizmu refleksji &#8211; ponieważ GWT nastawione jest na  maksymalną optymalizację i szybkość działania dynamiczne ładowanie bibliotek nie  jest dostępne; jednocześnie dostępna jest metoda getClass().getName();</li>
<li>strictfp nie jest dozwolone w GWT</li>
</ul>
<p>Oto pakiety które zawierają klasy dostępne w aplikacjach GWT (w niektórych przypadkach tylko niektóre fragmenty pakietu) to</p>
<ul>
<li><a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/doc/1.6/RefJreEmulation.html#Package_java_lang">java.lang</a></li>
<li><a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/doc/1.6/RefJreEmulation.html#Package_java_lang_annotation">java.lang.annotation</a></li>
<li><a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/doc/1.6/RefJreEmulation.html#Package_java_util">java.util</a></li>
<li><a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/doc/1.6/RefJreEmulation.html#Package_java_io">java.io</a></li>
<li><a rel="nofollow" href="http://code.google.com/intl/pl/webtoolkit/doc/1.6/RefJreEmulation.html#Package_java_sql">java.sql</a></li>
</ul>
<p>W ramach utrzymania pewnych funkcjonalności GWT udostępnia klasy</p>
<ul>
<li>com.google.gwt.i18n.client.DateTimeFormat: obsługuje część  funkcjonalności <tt>java.util.DateTimeFormat</tt>.</li>
<li>com.google.gwt.i18n.client.NumberFormat: obsługuje część  funkcjonalności <tt>java.util.NumberFormat</tt>.</li>
<li>com.google.gwt.user.client.rpc.IsSerializable : interfejs spełniający rolę  <tt>java.io.Serializable</tt> wykorzystywana przez GWT do wywoływania zdalnych  procedur (RPC)</li>
<li>com.google.gwt.user.client.Timer : uproszczona klasa  <tt>java.util.Timer</tt>, (z powodu jednowątkowości)</li>
</ul>
<p>GWT wydaje się być ciekawą alternatywą dla standardowej budowy interfejsów za pomocą elementów HTMLowych. W wolnych chwilach warto poeksperymentować i zobaczyć, co Google może wnieść do tematu budowania aplikacji internetowych.</p>
<p>Bibliografia:</p>
<p>- http://code.google.com/intl/pl/webtoolkit/</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.atena.pl/wstep-do-gwt/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

