Bon c'est parti ! Faites pas gaffes aux Débugs un peu partout;
Rendu.java:
Map.java :
Quand on clique sur la map, ca envoie un paquet de la forme 1/x ou x est l'id de la case cliquée au serveur qui la redistribue a tous les clients connectés. A chaque frame, on récupère les paquets recu et on split pour trier.
Je recois donc un paquet qui indique une case x.
Puis j'utilise le setCase qui va changer l'image de la case.
Ps: Les lignes d'erreurs sont fléchées. Ce qui pose problème est apparemment le fait d'apeller le setCase depuis un ActionListener, car cela marche très bien dans le constructeur de rendu.java
Merci d'avance
Rendu.java:
Code :
package tkweb;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.PrintWriter;
import javafx.scene.Group;
import javafx.scene.Parent;
import javax.swing.Timer;
/**
*
* @author TheTrope
*/
public class Rendu extends Parent{
int x = 0;
Group Ecran = new Group();
Map nmap;
private Connexion Connect;
private BufferedReader in;
private PrintWriter out;
private String msg=null;
public Rendu()
{
Connect = new Connexion();
out = Connect.getOut();
nmap = new Map(1,410,100,out);
Ecran.getChildren().add(nmap);
nmap.setCase(42);
this.getChildren().add(Ecran);
new Timer(33,taskPerformer).start();
}
ActionListener taskPerformer = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
msg = Connect.getMsg();
if(msg != null && !"".equals(msg))
{
System.out.println("Rc: "+msg);
String str[]=msg.split("/");
System.out.println("str:"+str[0]);
if(str[0].equals("1"))
{
-----------------------------------------> nmap.setCase(2);
System.out.println(Integer.parseInt(str[1]));
System.out.println("Marchhhhhheee");
}
}
nmap.setx(x);
x++;
//System.out.println(x);
}
};
}
Code :
package tkweb;
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;
private Group[] tabtiles;
private Group[] tabtilesnew;
private Group partMap;
private Group til = new Group();
private PrintWriter _out;
private ImageView tile;
public Map(int id, int mx, int my, PrintWriter out){
tabtiles = new Group[225];
partMap = new Group();
startx = mx;
starty = my;
startxm = mx;
startym = my;
xx = startx;
yy = starty;
currentx = 0;
currenty = 0;
_out = out;
while (currenty<15){
while (currentx<15){
tabtiles[idc] = new Group();
tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t1.png")));
tabtiles[idc].getChildren().add(tile);
tabtiles[idc].setTranslateX(xx+10);
tabtiles[idc].setTranslateY(yy);
partMap.getChildren().add(tabtiles[idc]);
xx +=30;
yy += 15;
currentx++;
idc++;
}
currenty++;
xx = startx -currenty*30;
yy = starty + currenty*15;
currentx=0;
}
// tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t2.png")));
//this.getChildren().add(partMap);
affm();
System.out.println("map cree");
this.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent me){
mouseX = (int) me.getX()-startxm-30;
mouseY = (int) me.getY()-startym;
caseX = (int) Math.floor((mouseY / 30) + (mouseX /60));
caseY = (int) Math.ceil((mouseY / 30) - (mouseX /60));
//System.out.println(mouseX+"/"+mouseY+"//"+caseX+"/"+caseY);
// tabtiles[(caseY-1)*13+caseX].setImg(2);
//tabtiles[2].setImg(2);
String msg = "1/"+Integer.toString((caseY-1)*15+caseX);
Emission msgsend = new Emission(msg, _out);
clic++;
}
});
}
public void setx(int x)
{
partMap.setTranslateX(x);
startxm++;
}
public void setCase(int c)
{
tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t2.png")));
------------------------------> tabtiles[c].getChildren().add(tile);
}
public Group getGroup()
{
return partMap;
}
public void affm()
{
this.getChildren().add(partMap);
tile = new ImageView(new Image(Tile.class.getResourceAsStream("img/t2.png")));
tabtiles[2].getChildren().add(tile);
}
}
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:114)
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)
Je recois donc un paquet qui indique une case x.
Puis j'utilise le setCase qui va changer l'image de la case.
Ps: Les lignes d'erreurs sont fléchées. Ce qui pose problème est apparemment le fait d'apeller le setCase depuis un ActionListener, car cela marche très bien dans le constructeur de rendu.java
Merci d'avance