Command Displayable Canvas Screen Command Listener Command BACK
고수준 추상 이벤트 ± Command 이벤트 ® Displayable 인터페이스를 통해 Canvas 또는 Screen등의 객체에 등록, 삭제 ® Command. Listener 인터페이스를 통해서 전달되어 적절한 처리를 하게됨 ± Command 유형 ® BACK, CANCEL, EXIT, HELP, ITEM, OK, SCREEN, STOP ± Command 메소드 ® get. Command. Type(), get. Label(), get. Priority()
모바일 자바의 좌표 ± MIDP 자바 좌표계 get. Width() (0, 0) get. Height() ± 원점의 좌표 변경 ® Translate(int x, int y) ® get. Translate. X() ® get. Translate. Y()
모바일 자바의 색상 ± 흑백 화면을 위한 그레이 스케일 색상표 ® 0 ~ 255 ® 0 : 검은색, 255 : 하얀색 ± 컬러화면을 위한 RGB 색상표 ® 0 ~ 255, 0 x 000000 ~ 0 x. FFFFFF ® 0 x 000000 : 검은색, 0 x. FFFFFF : 하얀색 ± 메소드 ® get. Blue. Component(), get. Freen. Component() ® get. Red. Component(), get. Gray. Scale(), get. Color() ® set. Color(), set. Gray. Scale()
Draw. Example 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. import javax. microedition. midlet. *; import javax. microedition. lcdui. *; public class Draw. Example. MIDlet extends MIDlet implements Command. Listener { Display display; Draw. Example. Canvas canvas; List list; String[] draw. Modes = { "Line", "Arc", "Rectangle" }; Command exit. Command = null; public Draw. Example. MIDlet() { display = Display. get. Display(this); list = new List("Draw. Example", List. IMPLICIT, draw. Modes, null); exit. Command = new Command("Exit", Command. EXIT, 0); list. add. Command(exit. Command); list. set. Command. Listener(this); 13. 14. 15. 16. canvas = new Draw. Example. Canvas(); 17. 18. }
Draw. Example(cont. ) 19. 20. 21. public void start. App() throws MIDlet. State. Change. Exception { display. set. Current(list); } 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. public void pause. App() { } public void destroy. App(boolean unconditional) throws MIDlet. State. Change. Exception { } public void go. Main. Menu() { display. set. Current(list); } public void command. Action(Command c, Displayable s) { if (c == List. SELECT_COMMAND) { int selected = list. get. Selected. Index(); canvas. set. Mode(draw. Modes[selected]); display. set. Current(canvas);
Draw. Example(cont. ) 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. } else if (c==exit. Command) { try { destroy. App(false); notify. Destroyed(); } catch (MIDlet. State. Change. Exception ex) { } } } class Draw. Example. Canvas extends Canvas { String mode; public Draw. Example. Canvas() { mode = null; } public void set. Mode(String mode) { this. mode = mode; }
Draw. Example(cont. ) 57. 58. 59. 60. 61. public void paint(Graphics g) { // 화면을 흰색으로 채웁니다 g. set. Gray. Scale(255); g. fill. Rect(0, 0, get. Width(), get. Height()); 62. if (mode==null) return; 63. if (mode. equals(draw. Modes[0])) { g. set. Gray. Scale(0); g. set. Stroke. Style(g. SOLID); g. draw. Line(20, 20, 90); g. set. Stroke. Style(g. DOTTED); g. draw. Line(60, 20, 60, 90); g. draw. String("SOLID", 20, g. HCENTER|g. BASELINE); g. draw. String("DOTTED", 60, 20, g. HCENTER|g. BASELINE); } else if (mode. equals(draw. Modes[1])) { g. set. Gray. Scale(0); g. draw. Arc(15, 30, 0, 135); g. draw. Arc(60, 15, 30, 0, 360); g. fill. Arc(15, 60, 30, 25, 0, 135); g. fill. Arc(60, 25, 0, 360); 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76.
Draw. Example(cont. ) 77. 78. 79. 80. 81. 82. 83. 84. } else if (mode. equals(draw. Modes[2])) { g. set. Gray. Scale(0); g. draw. Rect(5, 5, 30); g. draw. Round. Rect(40, 5, 30, 10); g. fill. Rect(5, 40, 30); g. fill. Round. Rect(40, 30, 5, 5); } } protected void key. Pressed(int key. Code) { go. Main. Menu(); } 85. 86. 87. } 88. 89. }
- Slides: 15