Swing Worker: funkcja get ()
Moim problemem jest to, że nie rozumiem, jakswingworker
działa, ponieważ staram się to zrobićfa=worker.get()
ponieważ mam długą metodę, która oblicza wiele punktów działających w tle, ponieważ nie chcę zamrozić mojego interfejsu i chcę, aby jej wyniki malowały obraz komponentu. Ale nie rozumiem, gdzie to się dzieje, kiedy to robięfa=worker.get()
ponieważ moja konsola drukuje"titi"
i umieściłem wiele innych wydruków, aby zobaczyć następną część programu, ale nikt nie jest drukowany. Pomóż mi dowiedzieć się, gdzie idzie kompilacjaget()
lub podczas jego wykonywania i jeśli masz pomysł, jak zaimplementować to, czego potrzebuję, każdy blok kodu jest mile widziany.
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);
}