prototype
This commit is contained in:
68
linea/ZoneDessin.java
Normal file
68
linea/ZoneDessin.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package linea;
|
||||
|
||||
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 {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// un booleen qui permet d'arreter l'animation (suspendre)
|
||||
protected boolean estArrete = false;
|
||||
|
||||
// liste des objets graphiques
|
||||
private ArrayList<ObjetGraphique> listeObjets = new ArrayList<ObjetGraphique>();
|
||||
|
||||
public ZoneDessin(){
|
||||
setLayout(new BorderLayout());
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
setBackground(new Color(220,170,0));
|
||||
}
|
||||
|
||||
// Ajout d'un objet graphique à la zone de dessin
|
||||
public void ajouterObjet(ObjetGraphique unObjet) {
|
||||
listeObjets.add(unObjet);
|
||||
}
|
||||
|
||||
public void arreter(){
|
||||
estArrete = true;
|
||||
}
|
||||
|
||||
public void demarrer(){
|
||||
estArrete = false;
|
||||
}
|
||||
|
||||
public void traiterBoucleAnimation(){
|
||||
if (estArrete==true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. on déplace chaque objet graphique
|
||||
for (ObjetGraphique obj : listeObjets){
|
||||
obj.Animer();
|
||||
}
|
||||
|
||||
// 2. on demande à redessiner
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
Graphics2D g2D = (Graphics2D) g;
|
||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// Afficher tous les objets
|
||||
for (ObjetGraphique obj : listeObjets) {
|
||||
obj.Afficher(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user