Results 1 to 6 of 6

Thread: How to use Font class in java?

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    How to use Font class in java?

    Hi All,

    I am beginner to the java programming language, with lots of confusion about the java concept. The advanced java concepts seems very tough to understand as compare to core java. In one of my project I have to make use of font class. But unfortunately I know nothing about this Font class. I wonder if anyone of you let me know something about the Font class of java language with a suitable java code example. I would really appreciate your help over Font class.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to use Font class in java?

    The Font class represents fonts, which are used to render text in a visible way. A font provides the information needed to map sequences of characters to sequences of glyphs and to render sequences of glyphs on Graphics and Component objects. A character is a symbol that represents an item such as a letter, a digit, or punctuation in an abstract way. A glyph is a shape used to render a character or a sequence of characters. In simple writing systems, such as Latin, typically one glyph represents one character. In general, however, characters and glyphs do not have one-to-one correspondence.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use Font class in java?

    I suggest you to refer following methods of Font class of java:
    • getStringBounds(String strg, int beginIndx, int limit, FontRenderContext frcn)
    • getStringBounds(String strg, FontRenderContext frcn)
    • getStringBounds(CharacterIterator cir, int beginIndx, int limit1, FontRenderContext frcn)
    • getStringBounds(char[] chars, int beginIndx, int limit1, FontRenderContext frcn)
    • getLineMetrics(String strg, int beginIndx, int limit1, FontRenderContext frcn)

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use Font class in java?

    Hi friend,

    Below I have given example of font class, which will give you something idea about the font class:
    Code:
    import java.awt.Font;
    import java.awt.Graphics;
    
    public class FontDemo extends JApplet {
      public void init() {
        FontPanel fontPanel01 = new FontPanel();
        getContentPane().add(fontPanel01, BorderLayout.CENTER);
      }
    
      public static void main(String[] arpgs) {
        FontPanel starPanel = new FontPanel();
    
        JFrame f1 = new JFrame("Font");
        f1.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        };
    
        f1.getContentPane().add(starPanel, BorderLayout.CENTER);
        f1.setSize(new Dimension(500, 200));
        f1.setVisible(true);
      }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use Font class in java?

    Please go through the following constructors of Font class:
    1. Font(String StrName, int style1, int sizeOfFont)
    2. Font(Map attributes1)
    3. equals(Object obj1)
    4. getFontName(Locale lc1)
    5. getFont(Map attributes1)

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use Font class in java?

    Example of Font class:
    Code:
    import java.awt.Font;
    import java.awt.FNLont.GlyphVector;
    
    public class FontSample extends JPanel
    {
        public void paint(Graphics g) {
            Graphics2D g02 = (Graphics2D)g;
    
            g02.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            
            String s = "Java Source and Support";
            Font FNLont = new Font("SeriFNL", Font.PLAIN, 24);
            FontRenderContext FNLrc = g02.getFontRenderContext();
    
            GlyphVector gv1 = FNLont.createGlyphVector(FNLrc, s);
            g02.drawGlyphVector(gv1, 40, 60);
          }
    
      public static void main(String[] arwgs) {
        JFrame FNL = new JFrame();
        FNL.getContentPane().add(new SimpleFont());
        FNL.setSize(300, 250);
        FNL.show();
      }
    }

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. Extending the Font class
    By TechGate in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 04:27 AM
  3. How to change font in java using Swing?
    By Coldman in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 11:06 AM
  4. Abstract class in Java
    By SoftWore in forum Software Development
    Replies: 3
    Last Post: 07-11-2009, 01:58 PM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,261,819.80161 seconds with 17 queries