JavaFX makes accessing remote data over HTTP really easy. Similar to the web browser's XMLHttpRequest (XHR) object, JavaFX exposes the HttpRequest object to interact with remote web servers. The following code snippet uses HttpRequest to retrieve HTML from Wikipedia var url = "http://en.wikipedia.org/wiki/JavaFX"; var http = HttpRequest { location: url method: HttpRequest.GET onInput: function(in: java.io.InputStream) { if(in.available() > 0){ println ("Printing result from {url}"); var reader:BufferedReader; try{ reader = new BufferedReader(new InputStreamReader(in)); var line; while((line = reader.readLine()) != null){ println(line) } }finally{ reader.close(); in.close(); } } }} http.start();When you run this code, it will spill out the content of Wikipedia entry for JavaFX as shown in the figure below. | The materials on this website represent a small sample of content loosely based on the book JavaFX Application Development Cookbook. The book offers far more content with over 80 recipes covering a range of topics from basics to advanced concepts. Buy the BookYou can get your copy of the book directly from the publisher. Click here to order! |

