00001 import javax.microedition.midlet.*;
00002 import javax.microedition.lcdui.*;
00003
00004 import java.util.*;
00005
00006 import javax.bluetooth.*;
00011 public class TicTacMain extends MIDlet implements CommandListener{
00013 static TicTacMain midlet;
00015 TicTacCanvas monCanvas;
00016
00018 Timer iTimer = new Timer();
00019
00021 TicTacCom com;
00022
00024 private final Command selectCmd = new Command("Select", Command.SCREEN, 2);
00025 private final Command exitCmd = new Command("Exit", Command.EXIT, 1);
00026
00028 private static final String[] menuLabels = { "Joueur 1", "Joueur 2" };
00029 private final List menu = new List("TicTacToe 3D, par Béatrice Frey et Cyril Crassin", List.IMPLICIT, menuLabels, null);
00030
00032 public TicTacMain() {
00033 TicTacMain.midlet = this;
00034
00035 menu.addCommand(exitCmd);
00036 menu.addCommand(selectCmd);
00037 menu.setCommandListener(this);
00038 }
00039
00041 public void startApp() {
00042 Display.getDisplay(this).setCurrent(menu);
00043 }
00044
00046 public void pauseApp() {
00047 }
00048
00050 public void destroyApp(boolean unconditional) {
00051 }
00052
00053
00055 public static void quitApp() {
00056 midlet.destroyApp(true);
00057 midlet.notifyDestroyed();
00058 midlet = null;
00059 }
00060
00062 public void restartApp() {
00063 com=null;
00064 monCanvas=null;
00065
00066 System.gc();
00067 startApp();
00068
00069 }
00070
00071
00073 class MyTimerTask extends TimerTask {
00074 public void run() {
00075 if( monCanvas != null ) {
00076 monCanvas.repaint();
00077 }
00078 }
00079 }
00080
00082 public void commandAction(Command c, Displayable d) {
00083 if (c == exitCmd) {
00084 destroyApp(true);
00085 notifyDestroyed();
00086 return;
00087 }
00088
00089
00090 if(menu.getSelectedIndex()==0)
00091 com=new TicTacComServer(this, menu.getSelectedIndex());
00092 else
00093 com=new TicTacComClient(this, menu.getSelectedIndex());
00094
00095 monCanvas= new TicTacCanvas(this, menu.getSelectedIndex()+1, com);
00096 iTimer.schedule( new MyTimerTask(), 0, 40 );
00097
00098 Display.getDisplay(this).setCurrent(monCanvas);
00099
00100 }
00101 }