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