* <a href="Exemple3.java">Exemple3.java</a>
*
* @author Arnaud Giersch <arnaud.giersch@univ-fcomte.fr>
- * @version Wed, 08 Oct 2014 21:29:23 +0200
-
+ * @version Thu Oct 9 16:03:46 2014 +0200
*/
public class DrawingWindow {
panel.repaint(x - r, y - r, 2 * r + 1, 2 * r + 1);
}
+ /**
+ * Dessine un triangle.
+ *
+ * Dessine un triangle défini par les coordonnées de ses sommets:
+ * (x1, y1), (x2, y2) et (x3, y3). Utilise la couleur de dessin
+ * courante.
+ *
+ * @see #fillTriangle
+ * @see #setColor
+ */
+
+ public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
+ Polygon poly = new Polygon();
+ poly.addPoint(x1, y1);
+ poly.addPoint(x2, y2);
+ poly.addPoint(x3, y3);
+ synchronized (image) {
+ graphics.drawPolygon(poly);
+ }
+ panel.repaint(poly.getBounds());
+ }
+
+ /**
+ * Dessine un triangle plein.
+ *
+ * Dessine un triangle plein défini par les coordonnées de ses
+ * sommets: (x1, y1), (x2, y2) et (x3, y3). Utilise la couleur de
+ * dessin courante.
+ *
+ * @see #drawTriangle
+ * @see #setColor
+ */
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
+ Polygon poly = new Polygon();
+ poly.addPoint(x1, y1);
+ poly.addPoint(x2, y2);
+ poly.addPoint(x3, y3);
+ synchronized (image) {
+ graphics.drawPolygon(poly);
+ graphics.fillPolygon(poly);
+ }
+ panel.repaint(poly.getBounds());
+ }
+
/**
* Écrit du texte.
*
public void keyTyped(KeyEvent e) { }
}
-
- // Sample tests
- public static void main(String[] args) {
- DrawingWindow w = new DrawingWindow("Test!", 800, 600);
-
- w.setColor("green");
- for (int i = 0; i < 12 + 1; i++) {
- int p = 10 * i + 10;
- w.drawLine(p, 0, p, 125);
- }
-
- w.setColor("black");
- for (int i = 0; i < 12; i++) {
- int p = 10 * i + 10;
-
- w.drawCircle(p, 25, i);
- w.fillCircle(p, 50, i);
-
- w.drawRect(p, 75, p + i, 75 + i);
- w.fillRect(p, 100, p + i, 100 + i);
- }
- }
}