Peintures des bords et intérieurs
des objets graphiques

WB01624_.gif (281 octets) RETOUR

</COMMENT> alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." Your browser is completely ignoring the &lt;APPLET&gt; tag!

StrokePaint.class

Fichier source

StrokePaint.java

/* Auteur: Nicolas JANEY         */
/* nicolas.janey@univ-fcomte.fr  */
/* Novembre 2001                 */

import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.applet.*;
import java.net.*;

public class StrokePaint extends Applet {

  private Image i = null ;
  private BufferedImage bi = null ;
  
  public void init() {
    setBackground(new Color(200,200,200)); 
    URL url = this.getDocumentBase();
    String adresse = "http://"+url.getHost()+"/IG/Java2D/Images/r1.gif" ;
    try {
      URL u = new URL(adresse);
      i = getImage(u) ; }
    catch (MalformedURLException e) { }
  }

  public void paint(Graphics g) {
    Graphics2D g2 =(Graphics2D) g;
    g2.setColor(new Color(0,0,0));
    BasicStroke bs1 = new BasicStroke(8,
      BasicStroke.CAP_SQUARE,
      BasicStroke.JOIN_ROUND);
    g2.setStroke(bs1);
    g2.draw(new Line2D.Double(30,10,260,30)) ;
    float dp2[] = { 7,2,5,3,4,8 };
    BasicStroke bs2 = new BasicStroke(2,
      BasicStroke.CAP_BUTT,
      BasicStroke.JOIN_ROUND,
      0,
      dp2,
      0);
    g2.setStroke(bs2);
    g2.draw(new Ellipse2D.Double(25,50,45,90)) ;
    float dp3[] = { 12,3,15,4,2,11 };
    BasicStroke bs3 = new BasicStroke(4,
      BasicStroke.CAP_BUTT,
      BasicStroke.JOIN_ROUND,
      0,
      dp3,
      0);
    g2.setStroke(bs3);
    g2.draw(new Rectangle(150,55,120,30)) ;
    Color c = new Color(120,100,70) ;
    g2.setPaint(c);
    g2.fill(new Ellipse2D.Double(90,50,45,90)) ;
    Color c1 = new Color(200,0,0) ;
    Color c2 = new Color(0,0,170) ;
    GradientPaint gp = new GradientPaint(0,0,c1,40,30,c2,true); 
    g2.setPaint(gp);
    g2.fill(new Rectangle(150,110,115,30)) ;
    Polygon p2 = new Polygon();
    p2.addPoint(30,180); 
    p2.addPoint(70,280); 
    p2.addPoint(170,250); 
    p2.addPoint(230,270); 
    p2.addPoint(280,160);
    bi = new BufferedImage(100,
                           166,
                           BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2D = bi.createGraphics();
    g2D.drawImage(i,0,0,this);
    TexturePaint tp = new TexturePaint(bi,new Rectangle2D.Double(0,0,50,83)); 
    g2.setPaint(tp);
    g2.fill(p2);
  }

  public String getAppletInfo() {
    return "Dessin des bords et remplissage sous Java 2D.";
  }
}

RETOUR