import java.io.*;
import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ChoiceGroup__Suchleiste extends MIDlet implements CommandListener{
Form form = new Form("");
TextField tfSuche = new TextField("Suche:","",20,TextField.ANY);
ChoiceGroup cGroup = new ChoiceGroup("Auswahl:",Choice.EXCLUSIVE);
static final Command exitCommand = new Command("Exit", Command.STOP, 2);
static final Command anrufen = new Command("Anrufen",Command.SCREEN, 1);
public ChoiceGroup__Suchleiste()
{
}
public Vector loadlist()
{
DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/buch.txt"));
StringBuffer sb = new StringBuffer();
Vector lines = new Vector();
int i=0 ;
try{
while ((i = dis.read()) > -1)
{
char ch = (char)i;
if (ch == '\n')
{ lines.addElement(sb.toString());
sb.delete(0,sb.length());
}
else
sb.append(ch);
}
dis.close();
}
catch (IOException e) {
e.printStackTrace();
}
return lines;
}
public void startApp() throws MIDletStateChangeException
{
Display d = Display.getDisplay(this);
d.setCurrent(form);
form.addCommand(exitCommand);
form.addCommand(anrufen);
form.setCommandListener(this);
Vector lines = loadlist();
for ( int i = 0; i < lines.size(); i++)
{
cGroup.append((String)lines.elementAt(i),null);
}
form.append(tfSuche);
form.append(cGroup);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
///////////// main menu
void mainMenu()
{
}
////////////Handle events.
public void commandAction(Command c, Displayable d)
{
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
if (c == anrufen) { // ein Eintrag aus dem Hauptmenu
switch(cGroup.getSelectedIndex()){
case 0: System.out.println("test");;
break;
case 1: System.out.println("test1");;
break;
case 2: System.out.println("test2");;
break;
}
}
}
}