`
chenliang1234576
  • 浏览: 195182 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
j2me实现二位坐标系 j2me,移动开发
package com.baiying.system.ui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class LineCanvas extends Canvas {

 private int screen_height = 0;
 private int screen_width  = 0;
 private int top_y  = 0;
 private int left_x = 0;
 private int line_width = 0;
 private int line_x = 0;
 private int line_h = 0;
 private int[] data = new int[]{20,-20,30,50,-10}; //坐标偏移量数据
 
 public LineCanvas(){
  screen_height = this.getHeight();
  screen_width = this.getWidth();
  top_y = screen_height/2;
  left_x = screen_width/5;
  line_width = screen_width*4/5;
  line_x = line_width/10;
  line_h = line_x/4;
 }
 
 protected void paint(Graphics g) {
  // TODO Auto-generated method stub
        g.drawLine(0, top_y, screen_width, top_y);       //画横坐标
        g.drawLine(left_x, 0, left_x, screen_height);    //画竖坐标
        // g.drawLine(left_x+line_x, top_y, left_x+line_x, top_y-line_h); //画坐标点
        g.drawString("0", left_x-8, top_y, Graphics.TOP|Graphics.LEFT);
        for(int i=1;i<9;i++){
          g.drawLine(left_x+line_x*i, top_y, left_x+line_x*i, top_y-line_h); //画坐标点
             g.drawString(new Integer(i).toString(), left_x+line_x*i, top_y, Graphics.TOP|Graphics.LEFT);
        }
        
      //  g.drawLine(left_x, top_y, left_x+20, top_y+30);
      //  g.drawLine(left_x+20, top_y+30, left_x+40, top_y+40);
        int n_data = 1;
        for(int i=0;i<5;i++){
            n_data = data[i];
            if(i>0){
               g.drawLine(left_x+line_x*i, top_y+data[i-1], left_x+line_x*(i+1), top_y+n_data);
            }else{
            g.drawLine(left_x+line_x*i, top_y, left_x+line_x*(i+1), top_y+n_data);
            }
        }
 }

}

Global site tag (gtag.js) - Google Analytics