Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual page 20

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
KeywordFilterDemoScreen screen = new KeywordFilterDemoScreen
(this,_keywordField);
screen.add(_keywordField.getKeywordField());
screen.add(_keywordField);
pushScreen(screen);
10. To create a method that populates and returns a vector of Country objects containing data from text file, In the method
signature, specify Vector as the return type.
public Vector getDataFromFile()
{
11.
Create and store a reference to a new Vector object.
Vector countries = new Vector();
12. Create an input stream to the text file.
InputStream stream = getClass().getResourceAsStream("/Data/
CountryData.txt");
13. Read CRLF delimited lines from the input stream.
LineReader lineReader = new LineReader(stream);
14. Read data from the input stream one line at a time until you reach the end of file flag. Each line is parsed to extract data
that is used to construct Country objects.
for(;;)
{
//Obtain a line of text from the text file
String line = new String(lineReader.readLine());
//If we are not at the end of the file, parse the line of text
if(!line.equals("EOF"))
{int space1 = line.indexOf(" ");
String country = line.substring(0,space1);
int space2 = line.indexOf(" ",space1+1);
String population = line.substring(space1
+1,space2);
String capital = line.substring(space2+1,line.length());
// Create a new Country object.
countries.addElement(new Country
(country,population,capital));
}
else
{
break;
}
}
// end the for loop
return countries;
}
15. To add a keyword to the list of selectable text items, invoke SortedReadableList.doAdd(element).
18
UI components

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents