fin
This commit is contained in:
BIN
DEV2.1/Polymophisme/ex3/Etoile.class
Normal file
BIN
DEV2.1/Polymophisme/ex3/Etoile.class
Normal file
Binary file not shown.
26
DEV2.1/Polymophisme/ex3/Etoile.java
Normal file
26
DEV2.1/Polymophisme/ex3/Etoile.java
Normal file
@@ -0,0 +1,26 @@
|
||||
import java.awt.Point;
|
||||
|
||||
public class Etoile implements ProducteurDePoints {
|
||||
private static final int xCentre = 100;
|
||||
private static final int yCentre = 100;
|
||||
private static final double rayon = 90.0;
|
||||
private static final double angleDepart = Math.PI/4.0;
|
||||
private static final double angleIncrement = (4.0*Math.PI)/5.0;
|
||||
private double numero;
|
||||
public Etoile() {
|
||||
this.numero = 0.0;
|
||||
}
|
||||
public Point suivant() {
|
||||
Point p = null;
|
||||
if (this.numero < 6.0) {
|
||||
double angle = Etoile.angleDepart+this.numero*Etoile.angleIncrement;
|
||||
p = new Point((int) (Etoile.rayon*Math.cos(angle)),
|
||||
(int) (Etoile.rayon*Math.sin(angle)));
|
||||
p.translate(Etoile.xCentre, Etoile.yCentre);
|
||||
this.numero++;
|
||||
} else {
|
||||
this.numero = 0.0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
BIN
DEV2.1/Polymophisme/ex3/Polyligne$1.class
Normal file
BIN
DEV2.1/Polymophisme/ex3/Polyligne$1.class
Normal file
Binary file not shown.
BIN
DEV2.1/Polymophisme/ex3/Polyligne.class
Normal file
BIN
DEV2.1/Polymophisme/ex3/Polyligne.class
Normal file
Binary file not shown.
44
DEV2.1/Polymophisme/ex3/Polyligne.java
Normal file
44
DEV2.1/Polymophisme/ex3/Polyligne.java
Normal file
@@ -0,0 +1,44 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Polyligne extends JFrame {
|
||||
private ProducteurDePoints producteurDePoints;
|
||||
|
||||
public Polyligne(ProducteurDePoints producteurDePoints) {
|
||||
this.producteurDePoints = producteurDePoints;
|
||||
|
||||
setTitle("Polyligne");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(300, 300);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
JPanel panel = new JPanel() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
|
||||
Point dernierPoint = null;
|
||||
Point pointActuel = producteurDePoints.suivant();
|
||||
while (pointActuel != null) {
|
||||
if (dernierPoint != null) {
|
||||
g2d.draw(new Line2D.Double(dernierPoint, pointActuel));
|
||||
}
|
||||
dernierPoint = pointActuel;
|
||||
pointActuel = producteurDePoints.suivant();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
add(panel);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ProducteurDePoints producteur = new Etoile(); // Changez ici pour utiliser votre propre fournisseur
|
||||
new Polyligne(producteur);
|
||||
}
|
||||
}
|
||||
BIN
DEV2.1/Polymophisme/ex3/ProducteurDePoints.class
Normal file
BIN
DEV2.1/Polymophisme/ex3/ProducteurDePoints.class
Normal file
Binary file not shown.
5
DEV2.1/Polymophisme/ex3/ProducteurDePoints.java
Normal file
5
DEV2.1/Polymophisme/ex3/ProducteurDePoints.java
Normal file
@@ -0,0 +1,5 @@
|
||||
import java.awt.Point;
|
||||
|
||||
public interface ProducteurDePoints {
|
||||
Point suivant();
|
||||
}
|
||||
Reference in New Issue
Block a user