艾,不想解释了。贴代码算了
java 代码
-
-
-
-
-
- package org.pook.ui;
-
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- import org.pook.ui.core.Platform;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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;
- }
-
- }
|