ListControl.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:3k
源码类别:
J2ME
开发平台:
Java
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.framework;
- import javax.microedition.lcdui.Graphics;
- /**
- *
- * @author santoshsalunke
- */
- class ListControl extends ScrollableContainer {
- GTantra font;
- TextControl[] text;
- String[] list;
- private int selectedIndex = 0;
- ComboBox parentcombo;
- protected ListControl(ComboBox parentcombo,GTantra font, int width, int selectedIndex,String list[]) {
- this.parentcombo = parentcombo;
- this.list = list;
- this.selectedIndex = selectedIndex;
- text = new TextControl[this.list.length];
- int _height = 0;
- for (int i = 0; i < this.list.length; i++) {
- text[i] = new TextControl(this.list[i], width, font, GTantra.TEXT_HCENTER,false);
- text[i].setPoistion(0, _height);
- text[i].setHeight(font.getFontHeight() + 2);
- text[i].setSelected(false);
- _height += (text[i].getHeight());
- addChildren(text[i]);
- }
- setTotalHeight(_height);
- if (height < totalHeight) {
- setWidth(width);
- }
- setVisible(false);
- selectChild(selectedIndex);
- }
- public boolean keyPressed(int keycode) {
- int gameKey = DisplayManager.getInst().getGameAction(keycode);
- if (gameKey == DisplayManager.UP) {
- selectedIndex--;
- if (selectedIndex < 0) {
- selectedIndex = this.list.length - 1;
- }
- selectChild(selectedIndex);
- return true;
- } else if (gameKey == DisplayManager.DOWN) {
- selectedIndex++;
- if (selectedIndex >= this.list.length) {
- selectedIndex = 0;
- }
- selectChild(selectedIndex);
- return true;
- } else {
- parentcombo.setText(getSelectedControl().getText());
- setVisible(false);
- DisplayManager.getInst().setListControl(null);
- return true;
- }
- }
- public void setSelected(boolean selected) {
- selectedChild = selectedIndex;
- super.setSelected(selected);
- }
- public void setWidth(int width) {
- super.setWidth(width);
- }
- public void setHeight(int height) {
- super.setHeight(height);
- selectChild(selectedIndex);
- }
- public TextControl getSelectedControl() {
- return (text[selectedChild]);
- }
- public void showNotify() {
- selectChild(selectedIndex);
- }
- public boolean keyPressedEvent(int keycode) {
- return false;
- }
- public void paintComponent(Graphics g) {
- }
- }