TOPIC 4_SLIDE NOTES
TOPIC 4_SLIDE NOTES
Implicit (Choice.IMPLICIT)
oSpecial exclusive list that combines selection and
confirmation as one process
Page 4 of 35 Dr. Mwakondo PhD (Computer Science) UoN
b. append method
Used to add elements in the list object i.e. end of list:
Format:
listVariable.append(“element”, null);
e.g. rervationList.append("Airplane”, null);
c. insert method
Used to add elements in the list object at a specified
position(index) in the list:
Format:
listVariable.insert(index, “element”, null);
e.g. rervationList.insert(0,"Airplane”, null);
Page 6 of 35 Dr. Mwakondo PhD (Computer Science) UoN
d. set method
Used to replace an element with a new one at a
specified position in the list:
Format:
AlertVariable.set(index, “newelement”,null);
e.g. rervationList.set(0,”Ferry”,null);
e. delete method
Used to remove an element at a specified position in
the list:
Format:
AlertVariable.delete(index);
e.g. rervationList.delete(0);
Page 7 of 35 Dr. Mwakondo PhD (Computer Science) UoN
e. deleteAll method
Used to remove every element in the list:
Format:
AlertVariable.deleteAll();
e.g. rervationList.deleteAll();
f. size method
Used to return number of elements in the list:
Format:
int number = AlertVariable.size();
e.g. int n = rervationList.size();
g. getString method
Used to return text label of an element at a specified
position in the list:
Page 8 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Format:
String label =listVariable.getString(index);
e.g. String name=reservationList.getString(2);
h. setFitPolicy method
Used to tell the list object on how to handle elements
whose text is wider than the screen:
These policies are defined in choice interface as:
wrap to multiple lines; Choice.TEXT_WRAP_ON
truncate at the edge; Choice.TEXT_WRAP_OFF
apply default; Choice.TEXT_WRAP_DEFAULT
Format:
AlertVariable.setFitPolicy(policyType type);
e.g. myList.setFitpolicy(Choice.TEXT_WRAP_ON);
Page 9 of 35 Dr. Mwakondo PhD (Computer Science) UoN
i. getSelectedIndex method
Used to return index of a selected element in the list:
Format:
int index =listVariable.getSelectedIndex();
e.g. index=reservationList.getSelectedIndex();
l. isSelected method
Used to return the selection status of the specified
element in the list:
Format:
Boolean status =listVariable.isSelected(index);
e.g. status = reservationList.isSelected(0);
Page 10 of 35 Dr. Mwakondo PhD (Computer Science) UoN
public mylistDemo1(){
myreservationList = new List("RESERVATION
TYPE",Choice.EXCLUSIVE);
myreservationList.append("Airplane", null);
myreservationList.append("Hotel", null);
myreservationList.append("Car", null);
myreservationList.set(2,"Ferry", null);
Page 11 of 35 Dr. Mwakondo PhD (Computer Science) UoN
display = Display.getDisplay(this);
}
public void startApp() {
display.setCurrent(myreservationList);
int n = myreservationList.size();
myAlert = new Alert("SIZE OF MY RESERVATION
LIST IS:");
myAlert.setString(Integer.toString(n));
display.setCurrent(myAlert);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Page 12 of 35 Dr. Mwakondo PhD (Computer Science) UoN
public myListDemo2(){
String myElements[] = {"Airplane","Hotel","Car"};
myreservationList = new List("RESERVATION
TYPE",Choice.EXCLUSIVE,myElements,null);
display = Display.getDisplay(this);
}
public void startApp() {
display.setCurrent(myreservationList);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Page 13 of 35 Dr. Mwakondo PhD (Computer Science) UoN
2. Spacer
Represents empty space in the form i.e. used for layout
purposes
Format:
Spacer spVariable=new Spacer(minWidth, minHeight);
e.g. Spacer mySpacer=new Spacer(12,6);
Member Methods:
a) none
3. TextField
Represents a labeled editable field where text can be
entered directly by either typing on the keyboard or
clicking number buttons.
Page 16 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Member Methods:
a) myItem.getLabel();//returns item’s label
b) myItem.setLabel(“label”);//replace label
Page 17 of 35 Dr. Mwakondo PhD (Computer Science) UoN
4. ImageItem
Represents an image that can be added in the form
Has three associated data items:
o label – may be displayed with the image
o layout – determines placement of an image
o alternate text – displayed if an image cannot be
shown
Note:
ImageItem layout can be controlled using layout
properties of the item class as discussed under the Form
Layout below:
Possible values for layout parameter:
Page 18 of 35 Dr. Mwakondo PhD (Computer Science) UoN
oLAYOUT_DEFAULT
oCombine horizontal values with vertical values
using bitwise operator:
oHorizontal values include: LAYOUT_LEFT,
LAYOUT_CENTER, or LAYOUT_RIGHT
oVertical values include:
LAYOUT_NEWLINE_BEFORE or
LAYOUT_NEWLINE_AFTER
Format:
ImageItem imgVariable=new ImageItem(label,image,layout,alternatetext);
e.g.
ImageItem myImage=new ImageItem (null,image,
ImageItem.LAYOUT_DEFAULT,”Waiting for the Image”);
OR
ImageItem imgVariable=new ImageItem(label,image,layout,alternatetext,
appearance);
Page 19 of 35 Dr. Mwakondo PhD (Computer Science) UoN
e.g.
ImageItem myImage=new ImageItem (null,image,
ImageItem.LAYOUT_DEFAULT,”Waiting for the Image”, null);
Member Methods:
a) myImage.getLabel();//returns image label
b) myImage.setLabel(“label”);//replace label
c) myImage.getAltText();//return alternate text
d) myItem.setAltText("text”);//replace alt.text
e) myImage.getImage();//returns image
f) myImage.setImage(“Image”);//replace image
g) myImage.getLayout();//return layout
h) myImage.setLayout(int Layout);//new layout
i) myImage.getAppearanceMode();//return mode
5. DateField
Page 20 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Format:
DateField dfVariable=new DateField(label,mode);
e.g.
DateField myDate=new DateField(“Date of Birth”,DateField.DATE);
OR
DateField dfVariable=new DateField(label,mode,TimeZone);
e.g.
DateField myDate=new DateField(“Date of Birth”,DateField.DATE,
TimeZone.DEFAULT);
Page 22 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Member Methods:
a) myDate.getLabel();//returns date label
b) myDate.setLabel(“label”);//replace label
c) myDate.getDate();//returns date
d) myDate.setDate(Date);//replace date
e) myImage.getInputMode();//return type
f) myItem.setInputMode(Type);//replace
6. Gauge
Represents a simple indicator showing progress or
status.
Has three associated data items:
o label – specifies the label
o type – specifies the type
o maxValue – specifies maximum range value
o initValue – specifies initial value of range
Page 23 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Member Methods:
a) myGauge.getLabel();//returns date label
b) myGauge.setLabel(“label”);//replace label
c) myGauge.getValue();//returns value
d) myGauge.setValue(Value);//replace value
e) myGauge.getMaxValue();//returns value
f) myGauge.setMaxValue(Value);//replace value
g) myGauge.setLayout(Layout);//sets layout
h) myGauge.isInteractive();//returns type
7. ChoiceGroup
Represents a list showing choices.
ChoiceGroup object implements choice interface that
defines the types of selections for the elements.
Its exactly similar to the normal list.
Page 25 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Note:
–Some of these items may include their own commands in
addition to commands that may be provided by the form
container.
Page 26 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Item.LAYOUT –
1. setLayout(LAYOUT_2,h,v,s)
LAYOUT_2 – item laid out using MIDP2 rules
h – horizontal value/position i.e. possible values:
oLAYOUT_RIGHT
oLAYOUT_LEFT
oLAYOUT_CENTER
v – vertical value/position i.e. possible values:
oLAYOUT_TOP
oLAYOUT_BOTTOM
oLAYOUT_VCENTER
s – space before or after item i.e. possible values:
oLAYOUT_NEWLINE_BEFORE
oLAYOUT_NEWLINE_AFTER
2. getLayout()
Page 28 of 35 Dr. Mwakondo PhD (Computer Science) UoN
Note:
Every item in the form has an index you can use to
retrieve them.
c. size method
Used to find out the number of items in the form
object.
Format:
Int n = frmVariable.size();
e.g. n = myForm.size();
d. get method
Used to retrieve an item in the form object.
Format:
Item thisItem= frmVariable.get(index);
e.g. Item thisItem = myForm.get(0);
Page 30 of 35 Dr. Mwakondo PhD (Computer Science) UoN
e. insert method
Used to add items in the form object at a specified
position (index):
Format:
frmVariable.insert(index, “itVariable”);
e.g. StringItem myItem=new StringItem("Name:”,”Ali”);
myForm.insert(0, myItem);
f. set method
Used to replace an item with a new one at a specified
position in the form:
Format:
StringItem itVariable=new StringItem(“label”,“text”);
frmVariable.set(index, “itVariable”);
e.g. StringItem myItem=new StringItem("Name:”,”Ali”);
myForm.set(0,myitem);
Page 31 of 35 Dr. Mwakondo PhD (Computer Science) UoN
g. delete method
Used to remove an item at a specified position in the
form:
Format:
frmVariable.delete(index);
e.g. myForm.delete(0);
h. deleteAll method
Used to remove every item in the form:
Format:
frmVariable.deleteAll();
e.g. myForm.deleteAll();
Page 32 of 35 Dr. Mwakondo PhD (Computer Science) UoN
public FormExample() {
myForm = new Form("Form Items");
myForm.append(mIncrementalGauge);
}
public void startApp() {
if (mDisplay == null) mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(myForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}