Main Page | Packages | Class List | Directories | File List | Class Members

TicTacMain.java

Go to the documentation of this file.
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;// = new TicTacCanvas();
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                 //Il n'y a que 2 boutons
00090                 com=new TicTacCom(this, menu.getSelectedIndex());
00091                 monCanvas= new TicTacCanvas(this, menu.getSelectedIndex()+1, com);
00092                 iTimer.schedule( new MyTimerTask(), 0, 40 );
00093                 
00094                 Display.getDisplay(this).setCurrent(monCanvas);
00095                 
00096         }  
00097 }

Generated on Sat Jun 11 20:13:59 2005 for TicTacToe3D by  doxygen 1.4.3