Suppose the following simplified example. Let B represent a class processing some raster data:
import java.awt.image.BufferedImage;
public class B implements Runnable{
private boolean c;
private Runnable f;
public B (boolean c_, Runnable f_) { c = c_; f = f_;}
public BufferedImage process() {
//Some operations
BufferedImage output = null;
if (c) output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
return output;
}
public void run() { process();}
}
The process() method may but may not create an output rater. Due to the computational cost, the procedure runs in a separate thread.
Let A represent a class inside which the procedure will be run. It also contains some post process steps waiting until the thread is finished:
import java.awt.image.BufferedImage;
public class A {
public A(){}
public void compute() {
boolean c = true;
B b = new B( c, new Runnable() {
public void run() {
//Post process, after the thread has been finished
BufferedImage img = ??? //Get resulting raster, how?
if (img != null) {
//Perform some steps
}
}
});
Thread t = new Thread(b);
t.start (); //Run procedure
}
}
However, how to get resulting raster created using the process() method of B "inside" the run() method in A?
Avoid the model, when the output image represents a data member of B together with
b.getImage();
I read a post about callbacks
but how to implement it here? Thanks for your help and a short example.