1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
public class ObjetVehicule extends JPanel implements MouseListener,
MouseMotionListener, Runnable{
....;
public ObjetVehicule(ObjetNoeud obNoeud)
{
currentNoeud= obNoeud;
noeudAttache = null;
iXCoord = (obNoeud.iXCoord-(LARGEUR/2));
firstX = iXCoord;
iYCoord = (obNoeud.iYCoord-(HAUTEUR/2));
this.setBounds(iXCoord, iYCoord, LARGEUR*2, LARGEUR*2);
InputStream input = getClass().getClassLoader().getResourceAsStream("ressources/vehicule.png");
try {
img = ImageIO.read(ObjetVehicule.class.getResource("/ressources/vehicule.png"));
} catch (IOException e) {
e.printStackTrace();
}
//BufferedImage
fAngle = 0;
vitesseSimulation = 10;
retourner = false;
enPause = false;
setLayout(null);
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
this.setBounds(iXCoord, iYCoord, LARGEUR, HAUTEUR);
setOpaque(false);
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform matrix = g2D.getTransform();
g2D.rotate(fAngle);
g2D.drawImage(img, 0, 0, LARGEUR, HAUTEUR, this);
g2D.setTransform(matrix);
}
...; |
Partager