以文本方式查看主题

-  课外天地 李树青  (http://njcie.com/bbs/index.asp)
--  JavaME移动开发课件  (http://njcie.com/bbs/list.asp?boardid=18)
----  程序代码——使用字体  (http://njcie.com/bbs/dispbbs.asp?boardid=18&id=554)

--  作者:admin
--  发布时间:2008/10/8 22:49:09
--  程序代码——使用字体

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet {
        private Display display;

        public Exec() {
                display = Display.getDisplay(this);
        }

        public void startApp() {

                display.setCurrent(new DrawPanel());
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }
}

class DrawPanel extends Canvas {
        public void paint(Graphics g) {
                String str = "NIIT 欢迎你";
                g.setColor(0, 0, 0);
                Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
                                Font.SIZE_LARGE);
                g.setFont(font);
                int fontWidth = font.stringWidth(str);
                int fontHeight = font.getHeight();
                g.drawString(str, getWidth() / 2 - fontWidth / 2, getHeight() / 2
                                - fontHeight / 2, Graphics.TOP | Graphics.LEFT);
        }
}

[此贴子已经被作者于2010-12-12 18:34:09编辑过]