原创作者: wuhua
阅读:1243次
评论:1条
更新时间:2011-05-26
艾,不想解释了。贴代码算了
java 代码
- /********************************************************************
- *
- * 版权说明,此程序仅供学习参考。不能用于商业
- *
- ********************************************************************/
- package org.pook.ui;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- import org.pook.ui.core.Platform;
- /**
- * <b>类名:ChoiceGroup.java</b> </br>
- * 编写日期: 2006-9-19 <br/>
- * 程序功能描述�? 本Class是一个多选择列表,因为项目的原�?,此列表是�?个固定形式的<br/>
- * 可以在Form上进行添加删�?,只不过表现形式固�?<br/>
- * Demo: <br/>
- * Bug: <br/>
- *
- * 程序变更日期 �?<br/>
- * 变更作�?? �?<br/>
- * 变更说明 �?<br/>
- *
- * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
- */
- public class Choice extends Part {
- private boolean select;
- /** 显示选择状�?? */
- private Image[] imageElements;
- public Choice(String label,
- Image[] imageElements, boolean select) {
- super(0, 0, 0, 0);
- if(label == null)
- label = "";
- this.label = label;
- this.select = select;
- this.imageElements = imageElements;
- }
- public void paint(Graphics g) {
- paintChoiceImpl(g);
- }
- private void paintChoiceImpl(Graphics g) {
- paintChoice(g);
- }
- private void paintChoice(Graphics g) {
- g.drawImage(select?imageElements[0]:imageElements[1],view[X], view[Y],
- Graphics.TOP|Graphics.LEFT);
- paintLabel(g);
- }
- private void paintLabel(Graphics g) {
- if(label.equals(""))
- return;
- g.setColor(fontColor);
- g.drawString(label,view[X] + imageElements[0].getWidth() + 4, view[Y]-2, Graphics.TOP | Graphics.LEFT);
- if(hasFocus)
- paintSelect(g);
- }
- /** 绘制选择�? **/
- private void paintSelect(Graphics g) {
- g.drawRect(view[X] - 1, view[Y] - 1,
- imageElements[0].getWidth() + 1,
- imageElements[0].getHeight() + 1);
- }
- public void onClick(int keyCode) {
- if(keyCode == Platform.KEY_ENTER
- && hasFocus)
- select = !select;
- }
- public boolean isSelect() {
- return select;
- }
- public void setSelect(boolean select) {
- this.select = select;
- }
- }
1 楼 ywhlhy 2011-07-25 15:18