Está usted en Indice > Construcción > Lenguajes > Java > Lecciones y Paso a Paso > Métodos tipos de letras en Java
Construcción
Maletín
Utilidades
Cursos
Promoción
Rentabilidad
Zona Novatos
Foros
Acceso a tu cuenta

Métodos tipos de letras en Java

// Métodos de FontMetrics y Graphics útiles para obtener métrica de tipos de letra.
2 import java.awt.*;
3 import javax.swing.*;
4
5 public class Metrica extends JFrame {
6
7 // establecer cadena de la barra de título y dimensiones de la ventana
8 public Metrica()
9 {
10 super( "Demostración de FontMetrics" );
11
12 setSize( 540, 210 );
13 setVisible( true );
14 }
15
16 // mostrar métrica del tipo de letra
17 public void paint( Graphics g )
18 {
19 super.paint( g ); // llamar al método paint de la superclase
20
21 g.setFont( new Font( "SansSerif", Font.BOLD, 12 ) );
22 FontMetrics metrica = g.getFontMetrics();
23 g.drawString( "Tipo de letra actual: " + g.getFont(), 10, 40 );
24 g.drawString( "Ascenso: " + metrica.getAscent(), 10, 55 );
25 g.drawString( "Descenso: " + metrica.getDescent(), 10, 70 );
26 g.drawString( "Altura: " + metrica.getHeight(), 10, 85 );
27 g.drawString( "Interlineado: " + metrica.getLeading(), 10, 100 );
28
29 Font font = new Font( "Serif", Font.ITALIC, 14 );
30 metrica = g.getFontMetrics( font );
31 g.setFont( font );
32 g.drawString( "Tipo de letra actual: " + font, 10, 130 );
33 g.drawString( "Ascenso: " + metrica.getAscent(), 10, 145 );
34 g.drawString( "Descenso: " + metrica.getDescent(), 10, 160 );
35 g.drawString( "Altura: " + metrica.getHeight(), 10, 175 );
36 g.drawString( "Interlineado: " + metrica.getLeading(), 10, 190 );
37
38 } // fin del método paint
39
40 // ejecutar la aplicación
41 public static void main( String args[] )
42 {
43 Metrica aplicacion = new Metrica();
44 aplicacion.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
45 }
46
47 } // fin de la clase Metrica




Autor: todojava.awardspace.com
http://todojava.awardspace.com/ejemplos-java.html?desc=Metrica

Usuarios que han visto este tema también han visto...

- Creando un JWizard con Swing
- Extendiendo el Runtime de Java con nuevos idiomas
- Escribir Applets paso a paso
- Deshabilitar todos los componentes incluidos en un Container Swing en Java
- Firma digital de un applet en Java


Versión imprimible - Versión imprimible de este documento
Enviar e-mail - Enviar por e-mail este documento
Publicidad

Información legal | Política de Privacidad | Contacte con nosotros

Otro proyecto de Factoría de Internet. Copyright© 2003-2008 Factoría de Internet S.L.. Todos los derechos reservados.


Página generada el 12-10-2008 a las 07:25:52