1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.microedition.lcdui;
21
22 public class StringItem extends Item {
23
24 StringComponent stringComponent;
25
26 public StringItem(String label, String text) {
27 this(label, text, PLAIN);
28 }
29
30 public StringItem(String label, String text, int appearanceMode) {
31 super(label);
32 stringComponent = new StringComponent(text);
33
34 }
35
36 public int getAppearanceMode() {
37
38 return Item.PLAIN;
39 }
40
41 public Font getFont() {
42
43 return Font.getDefaultFont();
44 }
45
46 public void setFont(Font font) {
47
48 }
49
50 public void setPreferredSize(int width, int height) {
51
52 }
53
54 public String getText() {
55 return stringComponent.getText();
56 }
57
58 public void setText(String text) {
59 stringComponent.setText(text);
60 repaint();
61 }
62
63 int getHeight() {
64 return super.getHeight() + stringComponent.getHeight();
65 }
66
67 int paint(Graphics g) {
68 super.paintContent(g);
69
70 g.translate(0, super.getHeight());
71 stringComponent.paint(g);
72 g.translate(0, -super.getHeight());
73
74 return getHeight();
75 }
76
77 int traverse(int gameKeyCode, int top, int bottom, boolean action) {
78 Font f = Font.getDefaultFont();
79
80 if (gameKeyCode == Canvas.UP) {
81 if (top > 0) {
82 if ((top % f.getHeight()) == 0) {
83 return -f.getHeight();
84 } else {
85 return -(top % f.getHeight());
86 }
87 } else {
88 return Item.OUTOFITEM;
89 }
90 }
91 if (gameKeyCode == Canvas.DOWN) {
92 if (bottom < getHeight()) {
93 if (getHeight() - bottom < f.getHeight()) {
94 return getHeight() - bottom;
95 } else {
96 return f.getHeight();
97 }
98 } else {
99 return Item.OUTOFITEM;
100 }
101 }
102
103 return 0;
104 }
105
106 }