update
This commit is contained in:
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.class
Normal file
Binary file not shown.
26
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.java
Normal file
26
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/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
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.class
Normal file
Binary file not shown.
27
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.java
Normal file
27
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.java
Normal file
@@ -0,0 +1,27 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/LigneAleatoire.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/LigneAleatoire.class
Normal file
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
import java.awt.Point;
|
||||
import java.util.*;
|
||||
|
||||
public class LigneAleatoire implements ProducteurDePoints {
|
||||
private int numero;
|
||||
|
||||
public LigneAleatoire() {
|
||||
this.numero = 0;
|
||||
}
|
||||
|
||||
public Point suivant() {
|
||||
Point p = null;
|
||||
if (this.numero < 10) {
|
||||
p = new Point(((int) (Math.random()*200)+50),
|
||||
((int) (Math.random()*200)+50));
|
||||
this.numero++;
|
||||
} else {
|
||||
this.numero = 0;
|
||||
}
|
||||
System.out.println(p);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
import java.awt.Point;
|
||||
|
||||
public interface ProducteurDePoints {
|
||||
Point suivant();
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.class
Normal file
Binary file not shown.
18
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java
Normal file
18
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java
Normal file
@@ -0,0 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Q3Main{
|
||||
public static void main(String[] args){
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
ProducteurDePoints producteur = new LigneAleatoire();
|
||||
//ProducteurDePoints producteur = new Etoile();
|
||||
Graphe dessin = new Graphe(producteur);
|
||||
fenetre.add(dessin);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
17
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java~
Normal file
17
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java~
Normal file
@@ -0,0 +1,17 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Q3Main{
|
||||
public static void main(String[] args){
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
ProducteurDePoints producteurEtoile = new Etoile();
|
||||
Graphe dessinEtoile = new Graphe(producteurEtoile);
|
||||
fenetre.add(dessinEtoile);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user