1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
@SuppressWarnings("serial")
abstract class Polygone1 extends FigureColoree{
Font PoliceNomTache;
private String etiquette;
/**
* Constructeur de la classe qui initialise les points représentant les sommets de Tache.
*/
public Polygone1(){
super();
for (int i=0 ; i<this.tab_mem.length ; i++)
tab_mem[i] = new UnPoint( (int)(Math.random()*600) , (int)(Math.random()*600) );
}
final static BasicStroke wideStroke = new BasicStroke(2.0f);
/**
* Méthode qui permet de dessiner et visualiser à l'écran la Tache
* @param g environnement graphique associé
*/
public void affiche(Graphics g){
g.drawPolygon( this.toPolygon());
Graphics2D g2 = (Graphics2D) g;{
super.affiche(g);
PoliceNomTache = new Font("Dialog", Font.BOLD, 12);
g.setFont(PoliceNomTache);
g2.setStroke(wideStroke);
g.drawString( ?????,tab_mem[0].rendreX()+3,tab_mem[0].rendreY()-20);
}
}
//DialogueEtiquette NomTache= new DialogueEtiquette(null);
/**
* Méthode qui permet de convertir une figure en polygone
* @return le polygone
*/
public Polygon toPolygon() {
int[] X = new int[this.tab_mem.length];
int[] Y = new int[this.tab_mem.length];
// stock abscisses et ordonnées des sommets du polygone dans un tableau.
for (int i=0 ; i < this.tab_mem.length ; i++) {
X[i] = this.tab_mem[i].rendreX();
Y[i] = this.tab_mem[i].rendreY();
}
Polygon p =new Polygon(X,Y,X.length);
return p;
}
/**
* Cette méthode retourne "vrai" si les coordonnées x et y passées en
* paramètre sont dans le polygone.
* @param x l'abscisse
* @param y l'ordonnée
* @return un booléen
*/
public boolean contient(int x, int y) {
Polygon p = this.toPolygon();
return p.contains(x,y);
}
} |
Partager