J'ai voulu faire une simulation d'explosion basique avec swing mais je me retrouve avec plein d'erreurs (une centaine) du type "at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)"...
Voici le fichier contenant le main :
import javax.swing.JFrame;
public class xay {
public static void main(String[] args){
Particule part = new Particule(10, 10, 0, 0);
Fenetre fenetre = new Fenetre(800, 600);
}
}
fenetre.java:
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Fenetre extends JFrame{
public Fenetre(int x, int y){
this.setTitle("Application...");
this.setSize(x, y);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(new Panneau());
this.setVisible(true);
}
}
Panneau.java (C'est la que va étre dessiné le rond représentant une particule, en fonction de ce qu'a renvoyé la fonction getx et gety de l'objet Particule) :
import java.awt.Graphics;
import javax.swing.JPanel;
public class Panneau extends JPanel{
public void paintComponent(Graphics g){
g.fillOval(part.getx(), part.gety(), part.getx()+2, part.gety()+2);
}
}
Et l'objet Particule :
public class Particule{
private int x;
private int y;
private int accx;
private int accy;
public Particule(int x, int y, int accx, int accy){
this.x = x;
this.y = y;
this.accx = accx;
this.accy = accy;
}
public void Evoluer()
{
x=x+accx;
y=y+accy;
}
public int getx()
{
return x;
}
public int gety()
{
return y;
}
}
import java.awt.Graphics;
import javax.swing.JPanel;
public class Panneau extends JPanel{
public void paintComponent(Graphics g){
g.fillOval(part.getx(), part.gety(), part.getx()+2, part.gety()+2);
}
}
Il sort d'ou ton objet part ? Il va pas se teleporter du main tout seul.
Problème objets avec swing
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.