1
private HBox addHBox() {

    HBox hbox = new HBox();
    hbox.setPadding(new Insets(15, 12, 15, 12));
    hbox.setSpacing(10);   // Gap between nodes
    hbox.setStyle("-fx-background-color: #336699;");

    TextField txtSearch = new TextField ();
    Button btnSubmit = new Button("Submit");

    hbox.getChildren().addAll(txtSearch, btnSubmit);

    return hbox;
} } 

this show my button code on an class and i want to use that button on another class.

Basically, this is the code in my another class and i want to link BtnSubmit on this class, how should i do it?

   ConfigurationBuilder configBuilder = new ConfigurationBuilder();
    configBuilder.setOAuthConsumerKey("");
    configBuilder.setOAuthConsumerSecret("");
    configBuilder.setOAuthAccessToken("");
    configBuilder.setOAuthAccessTokenSecret("");

    //Create instance of Twitter for searching etc.
    TwitterFactory tf = new TwitterFactory(configBuilder.build());
    Twitter twitter = tf.getInstance();

    btnSubmit.setOnAction((javafx.event.ActionEvent event) -> {
        Query query = new Query(txtSearch.getText());
        query.setLang("en");
        QueryResult result;
        query.setCount(100);
        int count = 0; 

        try {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            for (Status tweet : tweets) {
               String userName = tweet.getUser().getName();
               long userId = tweet.getUser().getId();
             //Date creationDate = tweet.getCreatedAt();
               String tweetText = tweet.getText();
               count++;

      System.out.println("Tweet created by " + userName + "(" + userId + ")" + count);
      System.out.println("Tweet text " + tweetText);
             }
        }
        catch(TwitterException ex){
        }
    });
  • 1
    Do you want to use a button that you declare in your addHbox function in an onther class than the one that your function is actually in ? – Mr Rubix Mar 28 '16 at 21:39
  • 1
    yes i want to use a button on addHbox function on another class – Dipak Mukesh Mar 28 '16 at 21:47
  • 1
    What about you return it in your function and link it to a public static button defined in the class. Then you will be able to use it in an other class – Mr Rubix Mar 28 '16 at 22:02
  • 1
    i did static button btnSubmit; and called it another class by doing import static firsttask.FirstTask.btnSubmit; however the button does not doing anything, any idea or clue? – Dipak Mukesh Mar 31 '16 at 17:34
  • Normaly you are supose to be able to access public static member of an other class with otherclass.member ! Maybe Mark McLaren - answer can help you [SOURCE](http://stackoverflow.com/questions/6576855/java-how-to-access-methods-from-another-class) – Mr Rubix Mar 31 '16 at 21:17

0 Answers0