17-02-2012, 11:11 AM
(Modification du message : 17-02-2012, 01:46 PM par Sephi-Chan.)
Hum dernière petite question :
Le code ci-dessus ne fonctionne pas, le problème vient du tabtiles[c].getChildren().add(tile); apperement, je peu bouger les groupes comme je le veux, mais quand j'essaie de modifier son contenu avec getChildren().add() voici l'erreur
import java.io.PrintWriter;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
public class Map extends Parent{
private int xx;
private int yy;
private int startx;
private int starty;
private int cl_mx;
private int cl_my;
private double mouseX;
private double mouseY;
private int caseX;
private int caseY;
private int currenty;
private int currentx;
private int idc =0;
private int clic =0;
private int startxm;
private int startym;
public Group[] tabtiles = new Group[200];
public Group[] tabtilesnew = new Group[200];
private Group partMap = new Group();
private Group til = new Group();
private PrintWriter _out;
private ImageView tile;
public Map(int id, int mx, int my, PrintWriter out){
startx = mx;
starty = my;
startxm = mx;
startym = my;
xx = startx;
yy = starty;
currentx = 0;
currenty = 0;
_out = out;
while (currenty<13){
while (currentx<13){
tabtiles[idc] = new Group();
tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t1.png")));
tabtiles[idc].getChildren().add(tile);
tabtiles[idc].setTranslateX(xx);
tabtiles[idc].setTranslateY(yy);
partMap.getChildren().add(tabtiles[idc]);
xx +=34;
yy += 17;
currentx++;
idc++;
}
currenty++;
xx = startx -currenty*34;
yy = starty + currenty*17;
currentx=0;
}
this.getChildren().add(partMap);
}
public void setx(int x)
{
partMap.setTranslateX(x);
startxm++;
}
public void setCase(int c)
{
tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t1.png")));
tabtiles[c].getChildren().add(tile);
}
}
Le code ci-dessus ne fonctionne pas, le problème vient du tabtiles[c].getChildren().add(tile); apperement, je peu bouger les groupes comme je le veux, mais quand j'essaie de modifier son contenu avec getChildren().add() voici l'erreur
Code :
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
at javafx.scene.Parent$1.onProposedChange(Unknown Source)
at com.sun.javafx.collections.VetoableObservableList.add(Unknown Source)
at com.sun.javafx.collections.ObservableListWrapper.add(Unknown Source)
at tkweb.Map.setCase(Map.java:108)
at tkweb.Rendu$1.actionPerformed(Rendu.java:54)
at javax.swing.Timer.fireActionPerformed(Timer.java:291)
at javax.swing.Timer$DoPostEvent.run(Timer.java:221)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD STOPPED (total time: 7 seconds)