SlideShare a Scribd company logo
1 of 33
Download to read offline
MIDP	
  GUI	
  Development:	
  	
  
 Alert,	
  List,	
  Form,	
  TextBox	
  

             Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Displayable	
  Class	
  Hierarchy	
  
javax.microedi-on.lcdui	
                                            javax.microedi-on.lcdui.game	
  




                           Displayable	
                Canvas	
             GameCanvas	
  



                                  Screen	
  




          Alert	
      List	
           Form	
     TextBox	
  
TextBox	
  
•  To	
  get	
  the	
  user	
  input	
  

•  TextBox a = new TextBox(String
   title, String text, int maxSize,
   int constraints)
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
TextBox	
  Usage	
  
TextBox textbox =
new TextBox("Sähköposti",
            "",
            64,
            TextField.EMAILADDR |
            TextField.PASSWORD);
Displayable	
  Class	
  Hierarchy	
  
javax.microedi-on.lcdui	
                                            javax.microedi-on.lcdui.game	
  




                           Displayable	
                Canvas	
             GameCanvas	
  



                                  Screen	
  




          Alert	
      List	
           Form	
     TextBox	
  
Alerts	
  
•  There	
  are	
  two	
  types	
  of	
  alerts	
  
    –  Timed	
  Alert	
  
         •  Displayed	
  certain	
  amount	
  of	
  Ime	
  
    –  Modal	
  Alert	
  
         •  Demands	
  user	
  confirmaIon	
  


                                                              Modal	
  Alert	
  
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!
Displayable	
  Class	
  Hierarchy	
  
javax.microedi-on.lcdui	
                                            javax.microedi-on.lcdui.game	
  




                           Displayable	
                Canvas	
             GameCanvas	
  



                                  Screen	
  




          Alert	
      List	
           Form	
     TextBox	
  
EXCLUSIVE,	
  MULTIPLE	
  and	
  IMPLICIT	
  
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.	
  
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() {}
}
List	
  Example	
  2	
  

public MyList() {
 String [] elements =
 {"hyytelöä", "kananmaksaa",
 "ituja"};


 mLista = new List("Haluatko
 ostaa?", Choice.MULTIPLE,
 elements, null);


 }
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)
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(...)	
  
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	
  
Displayable	
  Class	
  Hierarchy	
  
javax.microedi-on.lcdui	
                                            javax.microedi-on.lcdui.game	
  




                           Displayable	
                Canvas	
             GameCanvas	
  



                                  Screen	
  




          Alert	
      List	
           Form	
     TextBox	
  
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)!
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)!
Simple	
  Example	
  
mForm = new Form("Otsikko");
mForm.append("moi");
mForm.append("hei");
mForm.append("tere");
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!
Item	
  Layout	
  
•  Every	
  Form	
  item	
  can	
  have	
  a	
  layout:	
  
    –  LAYOUT_LEFT!
    –  LAYOUT_RIGHT!
    –  LAYOUT_CENTER!
    –  ...!
•  See	
  API!
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);
StringItem	
  
•  Represents	
  a	
  simple	
  “Label”

Form form = new Form("Title");
StringItem st = new StringItem("Label: ";
                               "Value");
form.append(stringItem);
Item:	
  Spacer	
  
•  Spacer	
  provides	
  empty	
  space	
  in	
  the	
  form.	
  
    –  Spacer empty = new Spacer(100,50); !
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...!
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()!
DateField	
  Images	
  
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 !
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);
Item:	
  ChoiceGroup	
  
•  Like	
  List	
  
     –  public ChoiceGroup(String label,
        int choiceType, String []
        elements, Image[] imageElements)!
•  Choicetype	
  
     –  EXCLUSIVE!
     –  MULTIPLE!
     –  MIDP 2.0: POPUP!
ChoiceGroup	
  Images	
  

String [] lista = {"suomi", "ruotsi"};
ChoiceGroup choicegroup = new ChoiceGroup("Valitse
maa", Choice.POPUP, lista, null);
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	
  

More Related Content

Viewers also liked

Viewers also liked (9)

J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
 
Introduction To J2ME(FT - Prasanjit Dey)
Introduction To J2ME(FT - Prasanjit Dey)Introduction To J2ME(FT - Prasanjit Dey)
Introduction To J2ME(FT - Prasanjit Dey)
 
Java ME CLDC MIDP
Java ME CLDC MIDPJava ME CLDC MIDP
Java ME CLDC MIDP
 
Session 3 J2ME Mobile Information Device Profile(MIDP) API
Session 3 J2ME Mobile Information Device Profile(MIDP)  APISession 3 J2ME Mobile Information Device Profile(MIDP)  API
Session 3 J2ME Mobile Information Device Profile(MIDP) API
 
Programowanie na komórki
Programowanie na komórkiProgramowanie na komórki
Programowanie na komórki
 
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
 
It6611 mobile application development laboratory l t p c0 0 3 2
It6611 mobile application development laboratory l t p c0 0 3 2It6611 mobile application development laboratory l t p c0 0 3 2
It6611 mobile application development laboratory l t p c0 0 3 2
 
Cs 6611 mad lab manual
Cs 6611 mad lab manualCs 6611 mad lab manual
Cs 6611 mad lab manual
 

Similar to MIDP GUI Development: Alert, List, Form, TextBox

Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
Fabrizio Giudici
 
Lists and scrollbars
Lists and scrollbarsLists and scrollbars
Lists and scrollbars
myrajendra
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
Text field and textarea
Text field and textareaText field and textarea
Text field and textarea
myrajendra
 

Similar to MIDP GUI Development: Alert, List, Form, TextBox (20)

Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 
Unit – I-AWT-updated.pptx
Unit – I-AWT-updated.pptxUnit – I-AWT-updated.pptx
Unit – I-AWT-updated.pptx
 
Lists and scrollbars
Lists and scrollbarsLists and scrollbars
Lists and scrollbars
 
Java
Java Java
Java
 
Python: The Dynamic!
Python: The Dynamic!Python: The Dynamic!
Python: The Dynamic!
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
 
GWT Widgets
GWT WidgetsGWT Widgets
GWT Widgets
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Java 103
Java 103Java 103
Java 103
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Text field and textarea
Text field and textareaText field and textarea
Text field and textarea
 
Introduction to JavaScript design patterns
Introduction to JavaScript design patternsIntroduction to JavaScript design patterns
Introduction to JavaScript design patterns
 

More from Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Recently uploaded

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

MIDP GUI Development: Alert, List, Form, TextBox

  • 1. MIDP  GUI  Development:     Alert,  List,  Form,  TextBox   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  • 3. TextBox   •  To  get  the  user  input   •  TextBox a = new TextBox(String title, String text, int maxSize, int constraints)
  • 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. TextBox  Usage   TextBox textbox = new TextBox("Sähköposti", "", 64, TextField.EMAILADDR | TextField.PASSWORD);
  • 6. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  • 7. Alerts   •  There  are  two  types  of  alerts   –  Timed  Alert   •  Displayed  certain  amount  of  Ime   –  Modal  Alert   •  Demands  user  confirmaIon   Modal  Alert  
  • 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. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  • 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. 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. List  Example  2   public MyList() { String [] elements = {"hyytelöä", "kananmaksaa", "ituja"}; mLista = new List("Haluatko ostaa?", Choice.MULTIPLE, elements, null); }
  • 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. 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. 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. Displayable  Class  Hierarchy   javax.microedi-on.lcdui   javax.microedi-on.lcdui.game   Displayable   Canvas   GameCanvas   Screen   Alert   List   Form   TextBox  
  • 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. 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. Simple  Example   mForm = new Form("Otsikko"); mForm.append("moi"); mForm.append("hei"); mForm.append("tere");
  • 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. Item  Layout   •  Every  Form  item  can  have  a  layout:   –  LAYOUT_LEFT! –  LAYOUT_RIGHT! –  LAYOUT_CENTER! –  ...! •  See  API!
  • 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. StringItem   •  Represents  a  simple  “Label” Form form = new Form("Title"); StringItem st = new StringItem("Label: "; "Value"); form.append(stringItem);
  • 25. Item:  Spacer   •  Spacer  provides  empty  space  in  the  form.   –  Spacer empty = new Spacer(100,50); !
  • 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. 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()!
  • 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. 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. Item:  ChoiceGroup   •  Like  List   –  public ChoiceGroup(String label, int choiceType, String [] elements, Image[] imageElements)! •  Choicetype   –  EXCLUSIVE! –  MULTIPLE! –  MIDP 2.0: POPUP!
  • 32. ChoiceGroup  Images   String [] lista = {"suomi", "ruotsi"}; ChoiceGroup choicegroup = new ChoiceGroup("Valitse maa", Choice.POPUP, lista, null);
  • 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