Pular para o conteúdo principal

Postagens

Mostrando postagens de abril, 2014

Writing JavaFX apps using Javascript with the Java 8 Nashorn engine

Java 8 was just a great release! We already talked about Lambdas and created JavaFX 8 apps on this blog. Bruno Borges created a fx2048 , a JavaFX version of the famous 2048 game, which shows Lambdas and the Stream library usage. Today I'll rewrite the Sentiments App view in Javascript using the new JS engine named Nashorn , one of the exciting Java 8 new features. Loading the Script We load a file with the view contents, but before doing this, we add the main Stage so it can be referenced from the javascript file. That's enough for the Java part! package org.jugvale.sentiments.view; import javafx.application.Application; import javafx.stage.Stage; import javax.script.*; import java.io.FileReader; public class AppJS extends Application{ private final String SCRIPT = getClass().getResource("/sentimentsView.js").getPath(); public static void main(String args[]){ launch(args); } @Override public voi...

Having fun creating a JavaFX App to Visualize Tweet Sentiments

A cool think that people loves to do is to create apps that analyze the sentiment of some text stream, such as Twitter. To better understand, see a graphical sentiment analysis for the Java 8 release messages on Twitter ( source ): In this post, I'm going to create a simple, really simple, app that queries twitter, and then access the Sentiment140 REST API to analyze the tweet's content sentiment. After this, I'll count the results in a chart and also list the text content in a table. Using the Sentiment140 REST API The API is really simple to use. Since I'm lazy, I love simplicity. To use it, submit a text and it will return a simple JSON with a number value called polarity, which possible values are: 0: negative 2:  neutral 4: positive The API documentation contains all the information you need to use it. Again, I simply loved how easy is to use it. For example, if I want to submit the text "I Love REST APIs" to the API, I would have to HTTP...