【用j2me提供的低级UI:CanvasImage和Graphics对象来绘制九宫格】

2.九宫格布局为主题区和底部菜单区
    3.将一张240*320的图片设置为背景图
    4.根据屏幕宽高计算出各图标的位置,然后绘制各图标。
    具体效果,如图所示:
    核心代码如下:
    public static final String[] filenames = { "/01.png", "/02.png", "/03.png",
    "/04.png", "/05.png", "/06.png" };
    public static final String[] labels = { "公文推送", "通知公告", "日程安排", "通讯录查询",
    "会议室查询", "手机邮箱" };
    public Image[] icons = new Image[9];
    public void paint(Graphics g) {
    int cw = this.getWidth();
    int ch = this.getHeight();
    try {
    // paintHead(g);
    this.setFullScreenMode(true);
    Image img = Image.createImage("/sliderbgn.JPG");
    // g.drawImage(img,0, 0, Graphics.TOP|Graphics.LEFT);
    g.drawImage(img, 0, 0, Graphics.TOP
    | Graphics.LEFT);
    for (int i = 0; i < filenames.length; i++) {
    try {
    icons[i] = Image.createImage(filenames[i]);
    } catch (IOException ex) {
    }
    }
    int old_color = g.getColor();
    g.setColor(0xffffff);
    int startY=ch/4;
    for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
    g.drawImage(icons[i * 3 + j], j * cw / 3 + 10, startY+i * ch*3 / 10,
    Graphics.TOP | Graphics.LEFT);
    g.drawString(labels[i * 3 + j], j * cw / 3 + 30, startY+i * ch*3 / 10
    + icons[i].getHeight(),
    Graphics.HCENTER | Graphics.TOP);
    }
    }
    g.setColor(old_color);
    paintBottom(g);
    } catch (Exception ex) {
    System.out.println(ex.toString());
    }
    }

更多精彩教程请关注:新番茄花园

转载于:https://www.cnblogs.com/mfxp/p/3255114.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值