Update JavaFX 2 GUI at intervals? -


i've spent last 24 hours trying learn javafx. i'm trying build gui display values data source (for example database). question preferred way this. far i've come code build simple gui , data data source:

import javafx.application.application; import javafx.application.platform; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.text.text; import javafx.stage.stage;  public class avchmi extends application {     public static void main(string[] args) {         launch(args);     }      @override     public void start(stage primarystage) {           text t = new text(10, 50, "replace/update text periodically data");                 group root = new group();         root.getchildren().add(t);          primarystage.setscene(new scene(root, 400, 300));         primarystage.show();          new thread() {             private datasource datasource = new datasource();              { setdaemon(true); }              @override             public void run() {                 try {                     for(;;) {                         thread.sleep(100);                          platform.runlater(new runnable() {                             @override                             public void run() {                                      system.out.println(datasource.getdatamap().get("key1"));                                                         }});                     }                 } catch(interruptedexception e) {                     e.printstacktrace();                 }             }         }.start();     } } 

datasource:

import java.util.hashmap; import java.util.map; import java.util.random;  public class datasource {     map<string,string> datamap = new hashmap<>();      public datasource() {         datamap.put("key1", "value1");         datamap.put("key2", "value2");         datamap.put("key3", "value3");     }      public map<string, string> getdatamap() {         random generator = new random();         int randint = generator.nextint();         datamap.put("key1", "value"+randint);         return datamap;     }   } 

100 ms ok interval update gui far i'm concerned. viable solution?

the next step replace text value data source. been looking @ collections , observablemap , wondering if it's preferred way of doing actual gui updates? i'm aving problems inner classes , final variables might reason out after sleep.

also, target machine not powerful (somewhere between 350-512 mb ram). issue? simple tests far seems run fine.

thank feedback on this.

this oracle example shows how achieve concurrency loading in data table, source code; might you

you @ reading javafx.concurrent.task<v> api.

the code on oracle example follows:

public class updatecustomertask extends task<customer> {          private final customer customer;           public updatecustomertask(customer customer) {              this.customer = customer;          }           @override protected customer call() throws exception {              // pseudo-code:              //   query database              //   read values               // update customer              platform.runlater(new runnable() {                  @override public void run() {                      customer.setf setfirstname(rs.getstring("firstname"));                      // etc                  }              });               return customer;          }      } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -