zoukankan      html  css  js  c++  java
  • J2ME游戏开发之字符串的绘制

    package com.sliw.graphics;
    
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    
    
    /**
     * 
     * @author 章伟
     *
     *
     
       1) face 为字体的外观,J2ME中提供了如下几种face:
           Font.FACE_SYSTEN
           Font.FACE_MONOSPACE
           Font.FACE_PROPORTIONAL
        
        2) style 为字体的风格,J2ME中提供了如下几种style:
           Font.STYLE_PLAIN
           Font.STYLE_BOLD
           Font.STYLE_ITALIC
           Font.STYLE_UNDERLINED
        其中,后三种可以混合使用,例:粗体加斜体的写法
        Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD|Font.STYLE_ITALIC, Font.SIZE_SMALL);
        
        3) size 为字体的大小,J2ME中提供了如下几种size:
           Font.SIZE_SMALL
           Font.SIZE_MEDIUM
           Font.SIZE_LARGE
     */
    public class StringCanvas extends Canvas{
    
        private int topY = 20;
        private int left = 10;
        private String s = "hello zhangweia!";
        
        protected void paint(Graphics g) {
            // TODO Auto-generated method stub
            clear(g);
            
            drawString(g);
        }
        
        
        public void drawString(Graphics g){
            
            Font font ;
            // getFont(int face, int style, int size)
            font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
            
            g.setFont(font);
            g.setColor(255,0,0);
            g.drawString(s, left, topY, Graphics.LEFT | Graphics.TOP);
            
            System.out.println("字符高度=" + font.getHeight() + "字符宽度=" + font.stringWidth(s));
            
            topY = topY + font.getHeight() + 20;
            g.drawSubstring(s, 0, 5, left, topY, Graphics.LEFT | Graphics.TOP);
            
            char c = 'a';
            topY = topY + 20;
            g.drawChar(c, left, topY, Graphics.LEFT | Graphics.TOP);
        }
        
        public void drawChar(){
            
        }
        
        private void clear(Graphics g){
            g.setColor(255,255,255);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    
    }
    
  • 相关阅读:
    EasyARM-iMX283A的Linux 开发环境构建
    linux指令tar笔记
    使用cuteFTP与虚拟机交互文件---安装ftp服务
    SecureCRT显示乱码的解决办法
    【转】简明 Vim 练级攻略
    图像识别___YUV学习手记
    一个简易的软件定时器
    OV7670配置和调试小结
    linux驱动开发( 五) 字符设备驱动框架的填充file_operations结构体中的操作函数(read write llseek unlocked_ioctl)
    hash-1.hash表和hash算法
  • 原文地址:https://www.cnblogs.com/zhangweia/p/2144084.html
Copyright © 2011-2022 走看看