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);    
        }
    }
    
  • 相关阅读:
    2018_10_15 堆栈内存
    2018_10_14 java 环境 win10
    2018_09_21 ftp 安装
    2018_09_21 myeclipse git插件
    转 iOS开发中一些常见的并行处理
    转【iOS设计】一款APP从设计稿到切图过程概述
    算法题
    iOS -copy-mutableCopy- NSHashTable -NSMapTable-Keychain
    转--iOS下JS与原生OC互相调用
    ReactiveCocoa
  • 原文地址:https://www.cnblogs.com/zhangweia/p/2143492.html
Copyright © 2011-2022 走看看