Hello

I have created application that will be changed prices after each 5 seconds
(loop), and next prices will be updated on view.

I'm using this solution
http://pivot.apache.org/tutorials/background-tasks.html for run task which
generating new prices. I have problem, because only one times are updating
prices - when this task is ended. I would like, for prices will be update
after each 5 seconds.

Could you explain my how implementing it?

My code:
public class MainViewTest implements Application {

public class MainViewTest implements Application {

        public static void main(String[] args) {

                DesktopApplicationContext.main(MainViewTest.class, args);
        }

        @Override
        public void startup(Display display, Map<String, String> properties)
                        throws Exception {

                final MainWindow main = new MainWindow();
                main.open(display);

                main.setListnerForPushButtonBuy(new ButtonPressListener() {

                        @Override
                        public void buttonPressed(Button button) {
                                UpdatePrice longCalculationTest = new 
UpdatePrice();
                                TaskListener<String> taskListener = new 
TaskListener<String>() {

                                        @Override
                                        public void taskExecuted(Task<String> 
task) {
                                                
main.setValueBalancedPrice(task.getResult());
                                        }

                                        @Override
                                        public void executeFailed(Task<String> 
task) {
                                                
System.err.println(task.getFault());
                                        }
                                };

                                longCalculationTest.execute(new 
TaskAdapter<>(taskListener));
                        }
                });

        }

        @Override
        public boolean shutdown(boolean optional) throws Exception {

                return false;
        }

        @Override
        public void suspend() throws Exception {

        }

        @Override
        public void resume() throws Exception {

        }
}

public class UpdatePrice extends Task<String> {

        public UpdatePrice() {

        }

        @Override
        public String execute() throws TaskExecutionException {

                try {

                        Thread.sleep(5000);

                } catch (InterruptedException ex) {
                        throw new TaskExecutionException(ex);
                }

                return "103";
        }
}




--
View this message in context: 
http://apache-pivot-users.399431.n3.nabble.com/Timer-in-application-tp4022622.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply via email to