Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. public void DoSomething(){ //this method is invoked when button is clicked
  2.         ExampleService s = new ExampleService();
  3.         s.setValue1(s1.getValue()); //s1,s2 - UI elements
  4.         s.setValue2(s2.getValue());
  5.         s.start();
  6.     };
  7.  
  8.     private static class ExampleService extends Service<Void> {
  9.         double value1,value2;
  10.         public double getValue1() {
  11.             return value1;
  12.         }
  13.  
  14.         public void setValue1(double value1) {
  15.             this.value1 = value1;
  16.         }
  17.  
  18.         public double getValue2() {
  19.             return value2;
  20.         }
  21.  
  22.         public void setValue2(double value2) {
  23.             this.value2 = value2;
  24.         }
  25.  
  26.         @Override
  27.         protected Task<Void> createTask() {
  28.             return new Task() {
  29.                 final double v1 = value1;
  30.                 final double v2 = value2;
  31.                 @Override
  32.                 protected Object call() throws Exception {
  33.                     while(!isCancelled())
  34.                         ExampleMethod(v1,v2); // I want this method to take arguments from UI elements at each iteration
  35.                     return null;
  36.                 }
  37.             };
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement