zoukankan      html  css  js  c++  java
  • J2ME游戏开发之几何图形的绘制

    1. 方法

    a. 绘制空心矩形:

           drawRect(int x, int y , int width, int height);

    b. 绘制实心矩形:

          fillRect(int x, int y , int width, int height);

    c. 绘制椭圆

    2. code

    package com.sliw.graphics;
    
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    
    public class GeometryCanvas extends Canvas{
    
        int startY = 10;
        int height = 20;
        int tip = 10;
        
        protected void paint(Graphics g) {
            // TODO Auto-generated method stub
            clear(g);
            
            /** 绘制空心的矩形 */
            drawBlankRect(g);    
            startY = startY + height + tip;
            
            /** 绘制实心的矩形**/
            drawFillRect(g);
            startY = startY + height + tip;
            
            /** 绘制空心椭圆  **/
            drawBlankOval(g);
            startY = startY + height + tip;
            
            /** 绘制实心椭圆 **/
            drawFillOval(g);
            startY = startY + height + tip;
            
            /** 绘制类似进度条 **/
            drawBlankAndFillOval(g);
            startY = startY + height + tip;
            
            
            /** 绘制圆**/
            drawCycle(g);
        }
    
        private void clear(Graphics g){
            g.setColor(255,255,255);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
        
        /**
         * drawRect(int x, int y , int width, int height);
         * @param g
         */
        private void drawBlankRect(Graphics g){
            
            g.setColor(255,0,0);    
            g.drawRect(10, startY, 100, height);
            
        }
        
        
        private void drawFillRect(Graphics g){
            
            g.setColor(0,255,0);
            g.fillRect(10, startY, 100, height);
        }
        
        
        /**
         * drawRoundRect(int x , int y , int width, int height, int arcWidth , int arcHeight);
         *         arcWidth 是左右弧衔接起来凑成的弧的宽度
         *         arcHeight 则是上下弧衔接起来凑成的弧的高度
         * @param g
         */
        private void drawBlankOval(Graphics g){
            g.setColor(0,0,255);    
            g.drawRoundRect(10, startY, 100, height, 20, 20);
        }
        
        private void drawFillOval(Graphics g){
            g.setColor(0,0,255);    
            g.fillRoundRect(10, startY, 100, height, 20, 20);
        }
        
        /**
         * 通过叠加的方式
         * @param g
         */
        private void drawBlankAndFillOval(Graphics g){
            g.setColor(0,0,255);    
            g.drawRoundRect(10, startY, 100, height, 20, 20);
            g.fillRoundRect(10, startY, 20, 20, 20, 20);
            g.fillRect(20, startY, 60, 20);
        }
        
        /**
         *   
         */
        private void drawCycle(Graphics g){
            g.setColor(150,150,150);
            g.drawRoundRect(10, startY, 60, 60, 60, 60);    
        }
    }
    
  • 相关阅读:
    WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
    WEB版一次选择多个文件进行批量上传(WebUploader)的解决方案
    WEB上传大文件解决方案
    kindeditor 富文本粘贴 图片
    Kindeditor图片粘贴上传(chrome)
    PHP超大文件下载,断点续传下载
    大文件断点上传 js+php
    常见的消息映射格式总结
    常见的消息映射格式总结
    C++项目中的extern "C" {}
  • 原文地址:https://www.cnblogs.com/zhangweia/p/2143492.html
Copyright © 2011-2022 走看看