Exemple d’utilisation de la classe ‘FontMetric’ pour obtenir des information sur la police actuelle

Author:

classe, set, java, swing, awt, JPanel, JFrame
{filelink=9427}

   import java.awt.Font;
   import java.awt.Color;
   import java.awt.Graphics;
   import javax.swing.*;
   import java.awt.FontMetrics;

   public class ExempleFontMetric extends JPanel
   {

    public void paintComponent( Graphics g )
    {
       super.paintComponent( g );

       g.setColor( Color.MAGENTA );  //Modifier la couleur du graphique

       // Définir une police pour le graphique
       g.setFont( new Font( "Serif", Font.BOLD + Font.ITALIC, 14 ) );

       // Définir un objet Metric pour obtenir des infos sur la police
       FontMetrics metrics = g.getFontMetrics();

       g.drawString( "Police courante: " + g.getFont(), 10, 40 );
       g.drawString( "ASCENT: " + metrics.getAscent(), 10, 55 );
       g.drawString( "DESCENT: " + metrics.getDescent(), 10, 70 );
       g.drawString( "HEIGHT: " + metrics.getHeight(), 10, 85 );
       g.drawString( "LEADING: " + metrics.getLeading(), 10, 100 );

    }
    	 // Fonction principale
    	public static void main (String[] args)
    		{
    		 JFrame frame=new JFrame("Police et la classe FontMetric")	;
    		 JPanel policePanel=new ExempleFontMetric();
    		 frame.add(policePanel);
    		 frame.setSize(300,200);
    		 frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    		 frame.setVisible(true);

            }
 }

A Voir sur le même Sujet:

  • java utiliser fontmetric
  • signification getleading fontmetrics
  • java connaitre la police local
  • la clase fontmetrics
  • fontmetrics a la ligne java
  • java utilisation fontmetrics
  • erreur srcfontmetrics
  • la classe fontmetrics;
  • fontmetric example
  • fontmetric

Leave a Reply

Your email address will not be published. Required fields are marked *