BUT2/DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.java
2023-10-23 13:23:36 +02:00

28 lines
759 B
Java

import javax.swing.JComponent;
import java.awt.*;
public class Graphe extends JComponent {
public ProducteurDePoints graphe;
public Graphe(ProducteurDePoints graphe){
this.graphe = graphe;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(Color.BLACK);
Point point1 = this.graphe.suivant();
Point point2 = this.graphe.suivant();
while (point2 != null){
secondPinceau.drawLine(point1.x, point1.y, point2.x, point2.y);
point1 = point2;
point2 = this.graphe.suivant();
}
}
}