当前位置:编程学习 > JAVA >>

找到一个表格控件,谁能告诉我怎么调用啊?

j2me表格控件CustomTable.java的代码如下:


package Table;

/***
 * @author JiangLiwen , danxy2008@163.com , 2006-11-7
 */

import javax.microedition.lcdui.*;

public class CustomTable extends CustomItem{
public int getPrefContentHeight(int width){
return 0;
}
public int getPrefContentWidth(int width){
return 0;
}
public int getMinContentHeight(){
return 0;
}
public int getMinContentWidth(){
return 0;
}
 

  /** 定义表的属性 */
  private int rows = 0;
  private int cols = 0;
  private int dx = 50;
  private int dy = 20;

  /** 定义颜色 */
  private final static int titleColor[] = { 206, 223, 239 };
  private final static int rowsColor1[] = { 230, 230, 230 };
  private final static int rowsColor2[] = { 181, 227, 231 };
  
  /** 表头数据 */
  private String[] titles;

  /** 表数据内容 */
  private String[][] datas;

  /** 定义显示窗口大小 */
  private final static int winX = 220;
  private final static int winY = 180;

  /** 是否有出现滚动条 */
  private boolean isscroll = false;

  /** 数据绘制起始坐标 */
  private int dataY = 0;

  /** 数据内容高度 */
  private int ch = 0;

  /** 数据显示高度 */
  private int vh = 0;

  /** 滚动条高度 */
  private int sh = 0;

  /** 滚动条区域高度 */
  private int ah = 0;

  /** 滚动的偏移量 */
  private int offset = 0;

  /** 滚动的速度 */
  private int speed = 0;

  /** 响应键盘事件 */
  boolean horz;

  

  /**
   * 构造函数
   * @param name , 表名
   * @param ptitle , 表头(一惟数组)
   * @param pdata , 表内容数据(二惟数组)
   */
  public CustomTable(String name, String[] ptitle, String[][] pdata) {
    super(name);
    cols = ptitle.length;
    rows = pdata.length;
    titles = ptitle;
    datas = pdata;
    //初始化滚动条信息
    ch = rows * dy;
    if (ch > (winY - 20)) {
      isscroll = true;
      vh = winY - dy - 4;
      ah = winY - 2 * dy - 4;
      sh = (int) ((ah * vh) / ch) - 10;
      speed = ch / ah;
    }
    //判断交互模式
    int interactionMode = getInteractionModes();
    horz = ((interactionMode & CustomItem.TRAVERSE_HORIZONTAL) != 0);
  }

  /**
   * 绘制函数
   */
  protected void paint(Graphics g, int w, int h) {
    int y = 0;
    int oldColor = g.getColor();
    
    // 设置表格数据样式
    for (int i = 0; i < rows; i++) {
      if (i % 2 == 0) {
        g.setColor(rowsColor1[0], rowsColor1[1], rowsColor1[2]);
      } else {
        g.setColor(rowsColor2[0], rowsColor2[1], rowsColor2[2]);
      }

      y = dataY + (i + 1) * dy + 1;
      if (y >= 0 || y <= winY) {
        for (int j = 0; j < cols; j++) {
          g.fillRect(j * dx + 1, y, dx - 1, dy - 1);
        }
        if (isscroll == false) {
          g.fillRect(winX - 19, y, winX, dy - 1);
        }
      }
    }
    // 添加表格数据
    g.setColor(oldColor);
    for (int i = 0; i < rows; i++) {
      if (y >= 0 || y <= winY) {
        y = dataY + (i + 1) * dy + 1;
        for (int j = 0; j < cols; j++) {
          g.drawString(datas[i][j], dx / 2 + j * dx, y,
              Graphics.HCENTER | Graphics.TOP);
        }
      }
    }

    // 清空
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, winX, 20);
    // 绘制表头区域
    int hx = winX;
    int hy = dy;
    g.setColor(titleColor[0], titleColor[1], titleColor[2]);
    g.fillRect(0, 0, hx, hy);
    // 绘制白色线条
    int temp = 0;
    g.setColor(255, 255, 255);
    g.drawLine(0, 0, hx, 0);
    for (int i = 0; i < cols; i++) {
      temp = i * dx + 1;
      g.drawLine(temp, 0, temp, hy);
    }
    // 绘制灰色线条
    g.setColor(128, 128, 128);
    g.drawLine(0, hy - 1, hx, hy - 1);
    for (int i = 0; i < cols; i++) {
      temp = (i + 1) * dx - 1;
      g.drawLine(temp, 1, temp, hy - 1);
    }
    // 填写标题数据
    g.setColor(0);
    for (int i = 0; i < cols; i++) {
      g.drawString(titles[i], dx / 2 + i * dx, 1, Graphics.HCENTER
          | Graphics.TOP);
    }
    // 补充表头右边边框
    g.setColor(255, 255, 255);
    g.drawLine(winX - 19, 1, winX - 19, dy - 1);
    g.setColor(128, 128, 128);
    g.drawLine(winX - 1, 1, winX - 1, dy - 1);
    // 绘制表底线条
    g.setColor(titleColor[0], titleColor[1], titleColor[2]);
    if (isscroll) {
      g.fillRect(0, winY - 2, winX - 20, 2);
    } else {
      g.fillRect(0, winY - 2, winX, 2);
    }
    // 绘制滚动条
    if (isscroll) {
      // 绘制滚动条背景
      g.setColor(220, 220, 220);
      g.fillRect(winX - 19, dy + 1, winX - 20 - 1, winY - dy - 20);
      // 绘制滚动条下面方块
      g.setColor(titleColor[0], titleColor[1], titleColor[2]);
      g.fillRect(winX - 19, winY - dy - 1, 19, dy);
      g.setColor(255, 255, 255);
      g.fillRect(winX - 19, winY - dy, 19, 1);
      g.fillRect(winX - 19, winY - dy, 1, dy - 1);
      g.setColor(128, 128, 128);
      g.fillRect(winX - 1, winY - dy, 1, dy - 1);
      g.fillRect(winX - 19, winY - 1, 19, 1);
      // 绘制滚动块
      g.setColor(titleColor[0], titleColor[1], titleColor[2]);
      g.fillRect(winX - 19, dy + offset, 19, sh);
      g.setColor(255, 255, 255);
      g.fillRect(winX - 19, dy + offset, 19, 1);
      g.fillRect(winX - 19, dy + offset, 1, sh);
      g.setColor(128, 128, 128);
      g.fillRect(winX - 1, dy + offset, 1, sh);
      g.fillRect(winX - 19, dy + offset + sh, 19, 1);
      // 绘制三角形
      g.setColor(255, 255, 255);
      g.fillTriangle(210, 5, 205, 15, 215, 15);
      g.fillTriangle(205, 188, 215, 188, 210, 198);
    }
  }

  // do something ...
}

--------------------编程问答-------------------- 已经解决  修改下里面的paint函数 用cavanse绘制出来 --------------------编程问答-------------------- 构造函数传参,调用具体的方法啊!! --------------------编程问答-------------------- 好迅速 --------------------编程问答-------------------- 楼主去百度搜这个  里面应该是你要的那个

 

产品型号:v3.0


开 发 商:TeamDev


应用平台:JAVA
关键字:

摘要:JxBrowser能在Windows、Linux、Mac OS X (Intel and PPC-based)平台上将Mozilla Firefox浏览器完美地整合到Java AWT/Swing应用程序里。该库程序使用Gecko设计引擎来转换HTML文档。因而保证了它能与许多Internet标准(如HTML 4、CSS、XML、JavaScript以及其它)兼容。
补充:Java ,  J2ME
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,