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());
        }
    
    }
    
  • 相关阅读:
    JVM虚拟机
    antd Table排序问题
    关于element-ui中el-container布满全局的问题!
    vue 安装css预处理器LESS
    mybatis官网
    Lombok安装及使用介绍
    thymeleaf中th:each的使用,遍历数组
    thymeleaf中th:text和th:utext的使用与区别
    SprongBoot项目的打包与启动
    SpringBoot简单学习
  • 原文地址:https://www.cnblogs.com/zhangweia/p/2144084.html
Copyright © 2011-2022 走看看