Files
projet-dev/src/ZoneDessin.java

65 lines
1.2 KiB
Java
Raw Normal View History

2026-02-02 11:40:03 +01:00
package linea;
2026-02-02 11:19:18 +01:00
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;
import javax.swing.JPanel;
public class ZoneDessin extends JPanel {
2026-02-02 11:19:18 +01:00
private static final long serialVersionUID = 1L;
protected ArrayList<ObjetGraphique> listeObjets = new ArrayList<ObjetGraphique>();
2026-02-02 11:19:18 +01:00
protected boolean estArrete = false;
2026-02-23 10:29:41 +01:00
public ZoneDessin() {
2026-02-02 11:19:18 +01:00
setLayout(new BorderLayout());
setPreferredSize(new Dimension(800, 600));
setBackground(new Color(0, 73, 220));
2026-02-02 11:19:18 +01:00
}
public void ajouterObjet(ObjetGraphique unObjet) {
2026-02-10 14:56:22 +01:00
listeObjets.add(unObjet);
2026-02-02 11:19:18 +01:00
}
2026-02-23 10:29:41 +01:00
public void arreter() {
2026-02-02 11:19:18 +01:00
estArrete = true;
}
2026-02-23 10:29:41 +01:00
public void demarrer() {
2026-02-02 11:19:18 +01:00
estArrete = false;
}
2026-02-23 10:29:41 +01:00
public void traiterBoucleAnimation() {
if (estArrete == true) {
2026-02-02 11:19:18 +01:00
return;
}
2026-02-10 14:56:22 +01:00
2026-02-23 10:29:41 +01:00
for (ObjetGraphique obj : listeObjets) {
2026-02-10 14:56:22 +01:00
obj.Animer();
2026-02-02 11:19:18 +01:00
}
2026-02-10 14:56:22 +01:00
repaint();
2026-02-02 11:19:18 +01:00
}
2026-02-02 11:19:18 +01:00
public void paintComponent(Graphics g) {
super.paintComponent(g);
2026-02-02 11:19:18 +01:00
Graphics2D g2D = (Graphics2D) g;
2026-02-23 10:29:41 +01:00
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
2026-02-10 14:56:22 +01:00
2026-02-23 10:29:41 +01:00
for (ObjetGraphique obj : listeObjets) {
obj.Afficher(g);
2026-02-10 14:56:22 +01:00
}
2026-02-02 11:19:18 +01:00
}
2026-02-23 10:29:41 +01:00
public void viderObjets() {
listeObjets.clear();
}
}