Discussion Board

Results 1 to 3 of 3

Thread: need help

  1. #1
    Registered User Amy1989's Avatar
    Join Date
    Jan 2011
    Posts
    3
    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 grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    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 prssupe's Avatar
    Join Date
    Dec 2009
    Posts
    376
    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. New to WAP, need help understanding the need of a gateway
    By jeffreycastro in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2006-02-21, 13:36
  5. 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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved