ThumbnailList.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.framework;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /**
- *
- * @author santosh_salunke
- */
- public class ThumbnailList extends UIControl{
- ScrollableContainer container;
- public ThumbnailList(int width,int height) {
- setWidth(width);
- setHeight(height);
- container = new ScrollableContainer();
- container.setPosition(0, 0);
- container.setWidth(width);
- container.setHeight(height);
- }
- public int getSelectedIndex()
- {
- return container.getSelectedChildIndex();
- }
- public void addElements(Image list[])
- {
- int _y = 0;
- int tmp = -1;
- for (int i = 0; i < list.length; i++) {
- ImageControl control = new ImageControl(list[i]);
- if(tmp == -1)
- {
- tmp = (getWidth() - (control.getWidth() << 1)) / 3;
- }
- if( i % 2 == 0)
- {
- control.setPoistion((tmp), _y);
- }else
- {
- control.setPoistion((tmp << 1) + control.getWidth(), _y);
- _y += control.getHeight() + tmp;
- }
- control.setSelectionBorderColor(selectionBorderColor);
- container.addChildren(control);
- }
- }
- public void removeAll()
- {
- container.removeAll();
- }
- public void paint(Graphics g) {
- container.paintUI(g);
- }
- public boolean keyPressed(int keycode) {
- boolean result = false;
- if(!(result = container.keyPressed(keycode)))
- return super.keyPressed(keycode);
- return result;
- }
- public void showNotify() {
- super.showNotify();
- container.showNotify();
- }
- public void setSelected(boolean selected) {
- super.setSelected(selected);
- container.setSelected(selected);
- }
- public void hideNotify() {
- super.hideNotify();
- container.hideNotify();
- }
- }