Corrigé du TP 1 : premiers pas pratiques

Lignes aléatoires

Fichier Lignes.java

import javax.swing.JApplet;
import java.awt.Graphics;
 
public class Lignes extends JApplet
{
    public void paint(Graphics g)
    {
        for(int i=0; i<100; ++i)
        {
            int x0 = (int)(Math.random()*100);
            int y0 = (int)(Math.random()*100);
            int x1 = (int)(Math.random()*100);
            int y1 = (int)(Math.random()*100);
 
            g.drawLine(x0, y0, x1, y1);
        }
    }
}

Fichier Lignes.html

<html>
<head>
    <title>Mon applet</title>
</head>
 
<body>
Ceci est mon applet :
<applet code="Lignes.class" width="100" height="100"></applet>
</body>
 
</html>

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*

Vous pouvez utiliser ces balises et attributs HTML : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>