Your SlideShare is downloading. ×
MIDP: Form Custom and Image Items
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

MIDP: Form Custom and Image Items

2,238
views

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,238
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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