Source Code : Font Canvas

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Font Canvas

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

public class FontCanvas extends Canvas {

  private Font systemFont, monospaceFont, proportionalFont;

  public FontCanvas() {
    this(Font.STYLE_PLAIN);
  }

  public FontCanvas(int style) {
    setStyle(style);
  }

  public void setStyle(int style) {
    systemFont = Font.getFont(Font.FACE_SYSTEM, style, Font.SIZE_MEDIUM);
    monospaceFont = Font.getFont(Font.FACE_MONOSPACE, style, Font.SIZE_MEDIUM);
    proportionalFont = Font.getFont(Font.FACE_PROPORTIONAL, style, Font.SIZE_MEDIUM);
  }
  public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    // Clear the Canvas.
    g.setGrayScale(255);
    g.fillRect(0, 0, w - 1, h - 1);
    g.setGrayScale(0);
    g.drawRect(0, 0, w - 1, h - 1);

    int x = w / 2;
    int y = 20;

    y += showFont(g, "System", x, y, systemFont);
    y += showFont(g, "Monospace", x, y, monospaceFont);
    y += showFont(g, "Proportional", x, y, proportionalFont);
  }

  private int showFont(Graphics g, String s, int x, int y, Font f) {
    g.setFont(f);
    g.drawString(s, x, y, Graphics.TOP | Graphics.HCENTER);
    return f.getHeight();
  }
}



           
       

Thank with us