From 123963640a2e980433e7ba6076bf97b8c1e1564b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 9 Oct 2014 14:29:33 +0200 Subject: [PATCH] Add comments to examples. --- Exemple1.java | 3 +++ Exemple2.java | 5 +++++ Exemple3.java | 6 ++++-- Hello.java | 3 +++ TODO | 1 - 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Exemple1.java b/Exemple1.java index 9a26184..5530ffd 100644 --- a/Exemple1.java +++ b/Exemple1.java @@ -1,8 +1,11 @@ public class Exemple1 { public static void main(String[] args) { + // Création de la fenêtre DrawingWindow w = new DrawingWindow("Exemple 1", 640, 480); + // Affichage d'un ensemble de lignes, du centre de la fenêtre + // vers les bords final int cx = w.width / 2; final int cy = w.height / 2; final int delta = 5; diff --git a/Exemple2.java b/Exemple2.java index 1cff9d9..0043e5b 100644 --- a/Exemple2.java +++ b/Exemple2.java @@ -3,10 +3,13 @@ import java.util.*; public class Exemple2 { public static void main(String[] args) { + // Création de la fenêtre DrawingWindow w = new DrawingWindow("Exemple 3", 640, 480); int width = Math.min(w.width - 1, w.height - 1) / 2; + // Affichage de rectangles concentriques, avec un dégradé de + // couleurs for (int z = 0; z <= width; z++) { float r, g, b; float s = 3.0f * z / width; @@ -25,7 +28,9 @@ public class Exemple2 { g = 0.0f; b = 1.0f - s; } + // On change la couleur de dessin... w.setColor(r, g, b); + // ... et on affiche un rectangle w.drawRect(z, z, w.width - 1 - z, w.height - 1 - z); } } diff --git a/Exemple3.java b/Exemple3.java index 2b488d1..4a6aff8 100644 --- a/Exemple3.java +++ b/Exemple3.java @@ -5,10 +5,12 @@ public class Exemple3 { static final Random random = new Random(); public static void main(String[] args) { + // Création de la fenêtre DrawingWindow w = new DrawingWindow("Exemple 3", 640, 480); - for (int i = 0; ; i++) { - + // Sans s'arrêter, affiche des lignes au hasard avec une + // couleur tirée aléatoirement + while (true) { int x1 = random.nextInt(w.width); int y1 = random.nextInt(w.height); int x2 = random.nextInt(w.width); diff --git a/Hello.java b/Hello.java index e7b6dfa..51dd9f5 100644 --- a/Hello.java +++ b/Hello.java @@ -1,8 +1,11 @@ public class Hello { public static void main(String[] args) { + // Création d'une fenêtre avec, en paramètres, son titre, sa + // largeur et sa hauteur DrawingWindow w = new DrawingWindow("Exemple 1", 640, 480); + // Affichage d'un court message au milieu de la fenêtre w.drawText(w.width / 2, w.height / 2, "Hello world!"); } } diff --git a/TODO b/TODO index 63a3bb2..056fbb0 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -* Add comments to examples * Add draw/fillTriangle * Add set(Bg)Color with int * Add waitMousePress -- 2.20.1