×

Discussion Board

Results 1 to 3 of 3

Thread: need help

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    need help

    hello friend
    i have a project in j2me and i'm totally lost so i wish someone could help me
    well it's how to use the( Canvas )class for change the font in j2me
    this is the class

    class FontCanvas extends Canvas {
    private Font mSystemFont, mMonospaceFont, mProportionalFont;

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

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

    public void setStyle(int style) {
    mSystemFont = Font.getFont(Font.FACE_SYSTEM, style, Font.SIZE_MEDIUM);
    mMonospaceFont = Font.getFont(Font.FACE_MONOSPACE, style, Font.SIZE_MEDIUM);
    mProportionalFont = Font.getFont(Font.FACE_PROPORTIONAL, style, Font.SIZE_MEDIUM);
    }


    public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

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

    y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mSystemFont);
    y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mMonospaceFont);
    y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mProportionalFont);
    }

    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();
    }
    }

    my question is how could I make this class change the font for any word I send to it from MIDlet class(another class) ?
    I mean in this code it's only change the font for "HELLO THISE IS MY PROG." sentence
    what is the changes that I should do it on this class to make do what I want?
    and I'll be thankful for u all
    my regards

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: need help

    Welcome to Forum Nokia!

    setFont() only has effect for the current paint() method. There is no way you can change the default font. You must set it each time you paint().

    Graham.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    376

    Re: need help

    series of setfont might be helpful

Similar Threads

  1. certificate problem? I can help u but I too need help
    By veda_scient in forum Mobile Java General
    Replies: 1
    Last Post: 2008-02-05, 19:55
  2. i need help people ? i need an answer ?
    By dakoz in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-01, 12:19
  3. Replies: 0
    Last Post: 2006-03-01, 08:46
  4. Replies: 1
    Last Post: 2003-07-31, 10:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×