MIDP GUI Development: Alert, List, Form, TextBox

3,898 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,898
On SlideShare
0
From Embeds
0
Number of Embeds
165
Actions
Shares
0
Downloads
100
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

MIDP GUI Development: Alert, List, Form, TextBox

  1. 1. MIDP  GUI  Development:     Alert,  List,  Form,  TextBox   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  2. 2. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  3. 3. TextBox   •  To  get  the  user  input   •  TextBox a = new TextBox(String title, String text, int maxSize, int constraints)
  4. 4. Types  and  Flags   •  Types   •  Flags   –  TextField.ANY –  TextField.PASSWORD –  TextField.NUMERIC –  TextField.UNEDITABLE –  TextField.DECIMAL –  TextField.NON_PREDICTIVE –  TextField.PHONENUMBER –  TextField.INITIAL_CAPS_WORD –  TextField. –  TextField.EMAILADDR INITIAL_CAPS_SENTENCE –  TextField.URL
  5. 5. TextBox  Usage   TextBox textbox = new TextBox("Sähköposti", "", 64, TextField.EMAILADDR | TextField.PASSWORD);
  6. 6. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  7. 7. Alerts   •  There  are  two  types  of  alerts   –  Timed  Alert   •  Displayed  certain  amount  of  Ime   –  Modal  Alert   •  Demands  user  confirmaIon   Modal  Alert  
  8. 8. Alert  -­‐  class   •  Constructor   –  public Alert(String title, String alertText, Image alertImage, AlertType alerttype);! •  Methods   –  setTimeOut(...)! –  setTimeOut(Alert.Forever)! –  addCommand(...)! •  AlertTypes   –  ALARM, CONFIRMATION, ERROR, INFO, WARNING!
  9. 9. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  10. 10. EXCLUSIVE,  MULTIPLE  and  IMPLICIT  
  11. 11. ConstrucIng  Lists   •  When  you  create  a  list,  you  define  list's   –  type  (EXCLUSIVE,  MULTIPLE,  IMPLICIT)   –  Itle   –  string  elements  and  images  (voluntary)   •  API:   –  public List(String title, int type): –  public List(String title, int type, String [] stringelements, Image [] imageElements); •  Scrolling  is  automaIcally  available   •  It  is  possibly  to  add  elements  to  the  list  with  append- method.  
  12. 12. List  Example  1   public class MyList extends MIDlet{ private List mList; public MyList() { mList = new List(”Wanna Buy?”, Choice.MULTIPLE); mList.append(“Herring”, null); mList.append(“Goose Liver”, null); mList.append(“Jelly”, null); } public void startApp() { Display.getDisplay(this).setCurrent(mList); } public void destroyApp(boolean unconditional) {} public void pauseApp() {} }
  13. 13. List  Example  2   public MyList() { String [] elements = {"hyytelöä", "kananmaksaa", "ituja"}; mLista = new List("Haluatko ostaa?", Choice.MULTIPLE, elements, null); }
  14. 14. Adding  and  Removing  List  elements   •  It  is  possible  to  add  and  remove  list  elements   •  The  elements  are  accessible  by  index  (0...n)   •  Replacing  a  element:  set(...)     •  Adding  element:  append(...)     •  Adding  element  to  a  certain  place:  insert(...) •  Finding  element:  String getString(int n) •  Removing  element:  void delete(int n)
  15. 15. MIDP  2.0  List   •  How  do  you  treat  the  elements,  if  they  don't   fit  into  mobile  device's  screen?   –  setPolicy(...);   •  Choice.TEXT_WRAP_ON,  Choice.TEXT_WRAP_OFF,   Choice.TEXT_WRAP_DEFAULT   •  Changing  the  font:   –  setFont(...)  
  16. 16. List  SelecIon   •  How  to  find  out  what  element  user  selected?   –  public boolean isSelected(int i)! –  public int getSelectedIndex()! –  public void setSelectedIndex(int i, boolean s)! •  See  ListExample.java  
  17. 17. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  18. 18. Intro  to  Form   •  Form  is  a  GUI-­‐component  that  can  hold  other  GUI-­‐ components     •  These  othe  GUI-­‐components  are  called  items.   •  If  there  are  many  items,  the  form  will  provide   scrolling  mechanism.   •  Constructors:   –  public Form(String title)! –  public Form(String title, Item[] items)!
  19. 19. Handling  Items   •  Adding  Items  to  the  Form:   –  Form a = new Form(“otsikko”);! –  a.append(Item item);! –  a.append(String str);! –  a.append(Image image);! •  Every  item  has  an  index:   –  a.set(int index, Item item)! –  a.insert(int index, Item item)! –  a.delete(int index)! •  Other  methods:   –  int size();! –  Item get(int index)!
  20. 20. Simple  Example   mForm = new Form("Otsikko"); mForm.append("moi"); mForm.append("hei"); mForm.append("tere");
  21. 21. Using  Items   •  There  are  many  items.   •  javax.microedition.lcdui.Item:! –  ChoiceGroup! –  CustomItem // We will look this..! –  DateField! –  Gauge! –  ImageItem // .. and this later! –  Spacer! –  StringItem! –  TextField!
  22. 22. Item  Layout   •  Every  Form  item  can  have  a  layout:   –  LAYOUT_LEFT! –  LAYOUT_RIGHT! –  LAYOUT_CENTER! –  ...! •  See  API!
  23. 23. Using  Item  Layout   StringItem layoutLeft = new StringItem("Layout: ", "LEFT"); layoutLeft.setLayout(Item.LAYOUT_LEFT); StringItem layoutCenter = new StringItem("Layout: ", "CENTER"); layoutCenter.setLayout(Item.LAYOUT_CENTER); StringItem layoutRight = new StringItem("Layout: ", "RIGHT"); layoutRight.setLayout(Item.LAYOUT_RIGHT); mForm.append(layoutLeft); mForm.append(layoutCenter); mForm.append(layoutRight);
  24. 24. StringItem   •  Represents  a  simple  “Label” Form form = new Form("Title"); StringItem st = new StringItem("Label: "; "Value"); form.append(stringItem);
  25. 25. Item:  Spacer   •  Spacer  provides  empty  space  in  the  form.   –  Spacer empty = new Spacer(100,50); !
  26. 26. Item:  TextField   •  TextField:   –  public TextField (String label, String text, int maxSize, int constraints)! •  Constraints  (same  as  in   TextBox)   –  ANY, NUMERIC, DECIMAL, PHONENUMBER, EMAILADDR, URL! –  PASSWORD, SENSITIVE; UNEDITABLE...!
  27. 27. Item:  DateField   •  Date  and  Time  input.   –  public DateField(String label, int mode)! –  public DateField(String label, int mode, TimeZone timezone)! •  mode   –  DATE, TIME, DATE_TIME! •  Get  and  Set-­‐methods:   –  public Date getDate()! –  public void setDate()!
  28. 28. DateField  Images  
  29. 29. Item:  Gauge   •  Gauge  presents  integer  in  a  graphical  form.   –  public Gauge(String label, boolean interactive, int maxValue, int initialValue) •  By  using  parameter  interacIve  it  is  possible  to  define   can  the  user  modify  the  gauge.   •  IniIalValue  can  also  be:   •  CONTINUOUS_IDLE ! •  INCREMENTAL_IDLE ! •  CONTINUOUS_RUNNING ! •  INCREMENTAL_UPDATING !
  30. 30. Gauge  Images   Gauge kake1 = new Gauge("Editoitava", true, 100, 0); Gauge kake2 = new Gauge("Ei-editoitava", false, 100, 50); Gauge kake3 = new Gauge("INCREMENTAL_UPDATING", false, Gauge.INDEFINITE, Gauge.INCREMENTAL_UPDATING); Gauge kake6 = new Gauge("CONTINUOUS_RUNNING", false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
  31. 31. Item:  ChoiceGroup   •  Like  List   –  public ChoiceGroup(String label, int choiceType, String [] elements, Image[] imageElements)! •  Choicetype   –  EXCLUSIVE! –  MULTIPLE! –  MIDP 2.0: POPUP!
  32. 32. ChoiceGroup  Images   String [] lista = {"suomi", "ruotsi"}; ChoiceGroup choicegroup = new ChoiceGroup("Valitse maa", Choice.POPUP, lista, null);
  33. 33. Items  and  Event  Handling   •  Instead  of  using  CommandListener  you  now   use  ItemStateListener.   •  Set  the  event  source  to  form  and  the  listener   has  to  implement  ItemStateListener  interface.   •  The  interface  has  only  one  method:   –  itemStateChanged(Item item)! •  Example  

×