MIDP GUI:  Custom and Image Items Jussi Pohjolainen TAMK University of Applied Sciences
Displayable Class Hierarchy javax.microedition.lcdui javax.microedition.lcdui.game Displayable Alert List Form TextBox Scr...
Form Form Item ChoiceGroup CustomItem DateField Gauge ImageItem StringItem TextField *
Custom Items <ul><li>Custom Items = Making your own custom item. </li></ul><ul><li>Inherit your own Custom Item from Custo...
Own Custom Item {abstract} CustomItem {abstract} int getPrefContentWidth(int height) {abstract} int getPrefContentHeight(i...
Custom Items method's <ul><li>int getPrefContentWidth(int height) </li></ul><ul><ul><li>returns the item's width </li></ul...
Events <ul><li>It is possible to write the following methods in your own Custom Item-class: </li></ul><ul><ul><li>void key...
Example <ul><li>class MyItem extends CustomItem </li></ul><ul><li>{ public MyItem(String a){ super(a); } </li></ul><ul><li...
Image Item <ul><li>Displaying Image in Form. </li></ul><ul><li>Constructors </li></ul><ul><ul><li>ImageItem(String label, ...
Image <ul><li>MIDP devices should support  atleast  png-format. </li></ul><ul><li>Creating Image-object: </li></ul><ul><ul...
Example <ul><li>// [ Save the picture in the res-folder ] </li></ul><ul><li>// Creating picture-object (must be inside  </...
Upcoming SlideShare
Loading in...5
×

MIDP: Form Custom and Image Items

2,280

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,280
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MIDP: Form Custom and Image Items

  1. 1. MIDP GUI: Custom and Image Items Jussi Pohjolainen TAMK University of Applied Sciences
  2. 2. Displayable Class Hierarchy javax.microedition.lcdui javax.microedition.lcdui.game Displayable Alert List Form TextBox Screen Canvas GameCanvas
  3. 3. Form Form Item ChoiceGroup CustomItem DateField Gauge ImageItem StringItem TextField *
  4. 4. Custom Items <ul><li>Custom Items = Making your own custom item. </li></ul><ul><li>Inherit your own Custom Item from CustomItem class. </li></ul><ul><li>CustomItem has following abstract methods </li></ul><ul><ul><li>int getPrefContentWidth(int height) </li></ul></ul><ul><ul><ul><li>Item's preferred width </li></ul></ul></ul><ul><ul><li>int getPrefContentHeight(int width) </li></ul></ul><ul><ul><ul><li>Item's preferred height </li></ul></ul></ul><ul><ul><li>int getMinContentWidth() </li></ul></ul><ul><ul><ul><li>Item's minimum width </li></ul></ul></ul><ul><ul><li>int getMinContentHeight() </li></ul></ul><ul><ul><ul><li>Item's minimum height </li></ul></ul></ul><ul><ul><li>void paint(Graphics g, int w, int h) </li></ul></ul>
  5. 5. Own Custom Item {abstract} CustomItem {abstract} int getPrefContentWidth(int height) {abstract} int getPrefContentHeight(int width) {abstract} int getMinContentWidth() {abstract} int getMinContentHeight() {abstract} void paint(Graphics g, int w, int h) MyItem Form Item * Create a class that inherites CustomItem Gauge ImageItem StringItem TextField
  6. 6. Custom Items method's <ul><li>int getPrefContentWidth(int height) </li></ul><ul><ul><li>returns the item's width </li></ul></ul><ul><ul><li>The parameter is height! &quot;What width do you want, if the height is 18?&quot; </li></ul></ul><ul><li>int getPrefContentHeight(int width) </li></ul><ul><ul><li>&quot;What height do you want, if the width is 18?&quot; </li></ul></ul>
  7. 7. Events <ul><li>It is possible to write the following methods in your own Custom Item-class: </li></ul><ul><ul><li>void keyPressed(int keyCode) </li></ul></ul><ul><ul><li>void keyReleased(int keyCode) </li></ul></ul><ul><ul><li>void keyRepeated(int keyCode) </li></ul></ul><ul><ul><li>void pointerPressed(int x, int y) </li></ul></ul><ul><ul><li>void pointerReleased(int x, int y) </li></ul></ul><ul><ul><li>void pointerDragged(int x, int y) </li></ul></ul><ul><li>KeyCode can be found in Canvas-class: </li></ul><ul><ul><li>Canvas.FIRE, Canvas.DOWN, Canvas.UP ... </li></ul></ul><ul><ul><li>Canvas.NUM0, Canvas.NUM1 ... </li></ul></ul>
  8. 8. Example <ul><li>class MyItem extends CustomItem </li></ul><ul><li>{ public MyItem(String a){ super(a); } </li></ul><ul><li>public int getMinContentWidth(){ return 100; } </li></ul><ul><li>public int getMinContentHeight(){ return 30; } </li></ul><ul><li>public int getPrefContentWidth(int h){ return getMinContentWidth(); } </li></ul><ul><li>public int getPrefContentHeight(int w){ return getMinContentHeight();} </li></ul><ul><li>public void paint(Graphics g, int w, int h){ </li></ul><ul><li>g.setColor(0xffffffff); </li></ul><ul><li>g.fillRect(0,0,w,h); </li></ul><ul><li>} </li></ul><ul><li>protected void keyPressed(int keyCode){ </li></ul><ul><li>if(getGameAction(keyCode) == Canvas.FIRE){ </li></ul><ul><li>// Do Something </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  9. 9. Image Item <ul><li>Displaying Image in Form. </li></ul><ul><li>Constructors </li></ul><ul><ul><li>ImageItem(String label, Image img, int layout, String altText) </li></ul></ul><ul><ul><li>ImageItem(String label, Image image, int layout, String altText, int appearanceMode) </li></ul></ul><ul><li>Typical set/get methods </li></ul>
  10. 10. Image <ul><li>MIDP devices should support atleast png-format. </li></ul><ul><li>Creating Image-object: </li></ul><ul><ul><li>Image picture = Image.createImage(...); </li></ul></ul><ul><li>There are many createImage-methods (see the api). </li></ul><ul><li>Maybe the easiest: </li></ul><ul><ul><li>public static Image createImage(String name) </li></ul></ul>
  11. 11. Example <ul><li>// [ Save the picture in the res-folder ] </li></ul><ul><li>// Creating picture-object (must be inside </li></ul><ul><li>// try-catch... </li></ul><ul><li>Image picture = Image.createImage(&quot;picture.png&quot;); </li></ul><ul><li>// Creating ImageItem-object </li></ul><ul><li>ImageItem item = new ImageItem(&quot;My Picture&quot;, picture, Item.LAYOUT_CENTER, &quot;&quot;); </li></ul><ul><li>// Adding ImageItem to Form </li></ul><ul><li>mMainForm.append(item); </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×