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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| import java.awt.* ;
import java.awt.Event.* ;
import java.awt.image.* ;
import javax.swing.* ;
import java.applet.* ;
import java.util.* ;
import java.awt.Font ;
import java.lang.Math.* ;
import java.io.*;
import java.net.* ;
import java.awt.geom.AffineTransform ;
//=================================
public class Charw extends Applet
//=================================
{
static BufferedImage pixelmap ; // référencement de la pixelmap
static Graphics2D g2d ; // référencement du graphique
public void init ()
{
int larg_appl = size().width ; // Récupération de la largeur
int haut_appl = size().height ; // Récupération de la hauteur
System.out.println ("Dimensions de l'appliquette="+larg_appl+" , "+haut_appl) ;
// - On crée la pixelmap avec les dimension définies dans la page html
pixelmap = new BufferedImage( larg_appl , haut_appl , BufferedImage.TYPE_INT_RGB ) ;
// - on place le graphique sur la pixelmap
g2d = (Graphics2D)pixelmap.getGraphics() ;
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING
, RenderingHints.VALUE_ANTIALIAS_ON
) ;
// - On remplit la pixelmap d'un dégradé (noir-vert :
for (int y = 0 ; y < haut_appl ; y++)
{ for (int x = 0 ; x < larg_appl ; x++)
{
int r = (int)(x * 100. / (double)(larg_appl)) ; // calcul du Rouge
int v = (int)(y * 100. / (double)(haut_appl)) ; // calcul du Verte
int b = 0 ; // pas de Bleu
int c = 255 << 24
| r << 16
| v << 8
| b ;
pixelmap.setRGB( x , y , c );
}
}
// - On encadre la pixelmap :
g2d.setColor(new Color(255,255,255)) ;
g2d.drawRect( 0 , 0 , larg_appl-1 , haut_appl-1 ) ;
//=========================== texte 1 ==============================================================
int x = 150 ; int y = 50 ; double angle = 30.0 ; // position du texte et angle de rotation
g2d.drawRect( x , y , 2 , 2 ) ; // on marque le pivot du texte à dessiner
Font fnt = new Font ("Monospaced", Font.BOLD + Font.ITALIC, 15);
g2d.setColor(new Color(60,200,200));
AffineTransform transformation = new AffineTransform() ;
transformation.setToTranslation( x , y) ;
transformation.setToRotation(Math.toRadians(angle)) ;
Font policeDerivee = fnt.deriveFont(transformation) ;
g2d.setFont (policeDerivee);
g2d.drawString ("J'ai des problèmes de rotation et de translation avec drawString !..."
, 0.0f,0.0f);
//=========================== texte 2===============================================================
x = 50 ; y = 150 ; angle = 15.0 ; // position du texte et angle de rotation
g2d.setColor(new Color(255,255,255)) ;
g2d.drawRect( x , y , 2 , 2 ) ; // on marque le pivot du texte à dessiner
fnt = new Font ("Serif", Font.BOLD + Font.ITALIC, 15);
g2d.setColor(new Color(128,255,0));
transformation = new AffineTransform() ;
transformation.setToRotation(Math.toRadians(angle)) ;
transformation.setToTranslation( x , y) ;
policeDerivee = fnt.deriveFont(transformation) ;
g2d.setFont (policeDerivee);
g2d.drawString ("J'ai des problèmes de rotation et de translation avec drawString !..."
, 0.0f,0.0f);
}
public void paint(Graphics g) // point d'entrée standard
{
g.drawImage(pixelmap, 0, 0, null) ;
}
} |
Partager