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 |
/* Get Available Font Family Names Example This java example shows how to get available font family names using getAvailableFontFamilyNames method of GraphicsEnvironment class. */ import java.applet.Applet; import java.awt.Graphics; import java.awt.GraphicsEnvironment; /* <applet code="GetAvailableFonts" width=200 height=200> </applet> */ public class GetAvailableFonts extends Applet{ public void paint(Graphics g){ /* * To get an object of GraphicsEnvironment, use * static GraphicsEnvironment getLocalGraphicsEnvironment() * method of GraphicsEnvironment class. * * This is a static method. */ GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); /* * To get available font family names use, * String[] getAvailableFontFamilyNames() * method of GraphicsEnvironment class. * * This method returns an array of strings * containing names of available font families. */ String fontNames[] = graphicsEnvironment.getAvailableFontFamilyNames(); int y = 20; for(int i=0; i < fontNames.length; i++){ //print font names g.drawString(fontNames[i], 10, y); y += 20; } } } |
Example Output
Add Comment