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 |
/* Get Available Font Objects Example This java example shows how to get available font objects using getAllFonts method of GraphicsEnvironment class. */ import java.applet.Applet; import java.awt.Font; import java.awt.Graphics; import java.awt.GraphicsEnvironment; /* <applet code="GetAllFontObjectsExample" width=200 height=200> </applet> */ public class GetAllFontObjectsExample 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 objects use, * Font[] getAllFonts() * method of GraphicsEnvironment class. * * This method returns an array of Font objects. * */ Font fonts[] = graphicsEnvironment.getAllFonts(); int y = 20; for(int i=0; i < fonts.length; i++){ //print font names g.drawString(fonts[i].getName(), 10, y); y += 20; } } } |
Example Output
Add Comment