|
package com.siemens.datagramtest;
import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.ChoiceGroup; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet;
public class DatagramMIDlet extends MIDlet implements CommandListener {
private static final String SERVER = "Server";
private static final String CLIENT = "Client";
private static final String[] names = { SERVER, CLIENT };
private static Display display;
private Form f;
ChoiceGroup cg;
private boolean isPaused;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command startCommand = new Command("Start", Command.ITEM, 1);
public DatagramMIDlet() { display = Display.getDisplay(this); f = new Form("Datagram Demo"); cg = new ChoiceGroup("Please select peer", Choice.EXCLUSIVE, names, null); f.append(cg);
f.addCommand(exitCommand); f.addCommand(startCommand); f.setCommandListener(this);
display.setCurrent(f); }
public static Display getDisplay() { return display; }
public boolean isPaused() { return isPaused; }
public void startApp() { isPaused = false; }
public void pauseApp() { isPaused = true; }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(true); notifyDestroyed(); } else if (c == startCommand) { String name = cg.getString(cg.getSelectedIndex()); if (name.equals(SERVER)) { Server server = new Server(this); server.start(); } else { Client client = new Client(this); client.start(); } } }
} |