Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, this is a complete JavaFX program that prints out tweets from a timeline. I have a problem displaying results in the scene of my
Hello, this is a complete JavaFX program that prints out tweets from a timeline. I have a problem displaying results in the scene of my JavaFX app. Can anyone help me?
import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.FlowPane; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.geometry.Insets; import javafx.event.ActionEvent; import javafx.event.EventHandler; import java.util.List; import twitter4j.*; import java.util.ArrayList; // import twitter4j.Status; // import twitter4j.TwitterException; // import twitter4j.TwitterFactory; import twitter4j.conf.ConfigurationBuilder; public class Client extends Application { // GUI controls private TextField tfSearch; private Button btnSearch; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { // Window title primaryStage.setTitle("Twitter Client"); // Search text field tfSearch = new TextField(); tfSearch.setPrefColumnCount(20); tfSearch.setPromptText("Enter a search string"); // Search button btnSearch = new Button("Search"); // Handle button event btnSearch.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { try { searchTwitter(tfSearch.getText()); } catch (TwitterException e) { e.printStackTrace(); } } }); primaryStage.show(); // Pane FlowPane pane = new FlowPane(); pane.setHgap(5); pane.setVgap(5); pane.getChildren().addAll(new Label("Search:"), tfSearch, btnSearch); pane.setPadding(new Insets(10, 10, 10, 10)); // Scene Scene scene = new Scene(pane, 400, 300); primaryStage.setScene(scene); primaryStage.show(); } public static void searchTwitter(String searchString) throws TwitterException { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true); configurationBuilder.setOAuthConsumerKey(""); configurationBuilder.setOAuthConsumerSecret(""); configurationBuilder.setOAuthAccessToken(""); configurationBuilder.setOAuthAccessTokenSecret(""); //configurationBuilder.setUseSSL(true); TwitterFactory tf = new TwitterFactory(configurationBuilder.build()); twitter4j.Twitter twitter = tf.getInstance(); try { ResponseList a = twitter.getHomeTimeline(new Paging(1, 5)); for (Status b : a) { System.out.println(b.getText()); } } catch (Exception e) { System.out.println(e); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started