My problem is that I don't understand how the swingworker
works because what I'm trying to do is to make fa=worker.get()
because I have a long method which compute a lot of points running in background because I don't want to freeze my interface and I want to get her results to paint the component image. But I don't understand where it goes when I do fa=worker.get()
because my console prints "titi"
and I put a lot of other printing to see the next part of program reached but no one is printed. Please help me to know where the compilation goes after get()
or while it execute it and if you have an idea of how to implements what I need every block of code is welcome.
public void paintComponent(final Graphics g1){
// TODO Auto-generated method stub
final int width=getWidth();
final int height=getHeight();
image= new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
//On transforme le rectangle de base en un rectangle qui a le meme ratio que le cadre contenant l'ancien
//(Il yaura dessus la meme fractale mais avec plus de fond noir) afin que l'on puisse zoomer sans deformer la fractale
frame = frame.expandToAspectRatio((double)getWidth()/getHeight());
FlameAccumulator fa=null;
worker= new SwingWorker<FlameAccumulator,FlameAccumulator>(){
@Override
protected FlameAccumulator doInBackground() throws Exception {
// TODO Auto-generated method stub
System.out.println("exception");
return builder.build().compute(frame,width,height,density);
}
};
try {
System.out.println("titi");
fa=worker.get();
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Graphics g0=(Graphics2D)g1;
if(fa==null){
System.out.println("toto");
for (int i = 0; i <height; i++) {
for (int j = 0; j < width; j++) {
image.setRGB(j,i,0);
}
}
}
else{
System.out.println("tata");
for (int i = 0; i <height; i++) {
for (int j = 0; j < width; j++) {
image.setRGB(j,i,fa.color(palette, background, j, height-1-i).asPackedRGB());
}
}
}
g0.drawImage(image,0,0,null);
}