Java Reference
In-Depth Information
textBox.setCommandListener(this);
textBox.addCommand (backCmd);
if (descriptions.size() == 0)
readNews();
}
public void readNews() {
try {
HttpConnection httpConnection =
(HttpConnection) Connector.open (URL);
kXMLElement xml = new kXMLElement();
xml.parseFromReader (new InputStreamReader
(httpConnection.openInputStream()));
for (Enumeration e = xml.enumerateChildren();
e.hasMoreElements();)
readStory ((kXMLElement) e.nextElement());
}
catch (IOException e) {
newsList.append ("Error", null);
descriptions.addElement (e.toString());
}
}
/** Read a story and append it to the list */
public void readStory (kXMLElement story) {
String title = null;
String description = null;
for (Enumeration e = story.enumerateChildren();
e.hasMoreElements(); ) {
kXMLElement field = (kXMLElement) e.nextElement();
if (field.getTagName().equals ("title"))
title = field.getContents();
else if (field.getTagName().equals ("description"))
description = field.getContents();
}
if (title !=null){
descriptions.addElement
(description !=null ?description :title);
newsList.append (title,null);
}
}
public void pauseApp() {
}
public void commandAction (Command c, Displayable d) {
if (c == List.SELECT_COMMAND) {
String text = (String) descriptions.elementAt
(newsList.getSelectedIndex());
Search WWH ::




Custom Search