Main.java

/*
 * Copyright © 2011 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners. 
 * See LICENSE.TXT for license information.
 */   

package com.nokia.example.racer;


import com.nokia.example.racer.views.GameView;
import com.nokia.example.racer.views.Menu;
import com.nokia.example.racer.views.Settings;
import com.nokia.example.racer.views.Splash;
import com.nokia.example.racer.views.TouchGameView;
import com.nokia.mid.ui.gestures.GestureInteractiveZone;
import com.nokia.mid.ui.gestures.GestureRegistrationManager;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

public class Main extends MIDlet implements ExitListener{

    private Display display;

    private static Main self;

    private TouchGameView touchGameView;
    private Menu menu;
    private Settings settings;

    public static Main getInstance() {
        return self;

    }

    public void startApp() {

        if(display == null) {
            display = Display.getDisplay(this);
            self = this;
            Splash splash = new Splash();
            display.setCurrent(splash);
            new Thread() {
                public void run() {
                    
                    try {
                        sleep(1000);
                    }catch(InterruptedException e) {
                        
                    }
                    menu = new Menu();
                    settings = new Settings();
                    GestureInteractiveZone giz = new GestureInteractiveZone(GestureInteractiveZone.GESTURE_ALL);
                    touchGameView = new TouchGameView();
                    //touchGameView.setTrack(new Seissenberg(touchGameView));
                    GestureRegistrationManager.register(touchGameView, giz);
                    GestureRegistrationManager.setListener(touchGameView, touchGameView);
                    
                    display.setCurrent(menu);
                    
                    try {
                        join();
                    }catch(InterruptedException e) {
                        
                    }
                    
                }
            }.start();
            splash = null;
        }
    }
    public void showGameView() {
        display.setCurrent(touchGameView);
    }

    public void showMenu() {
        display.setCurrent(menu);
    }

    public void pauseApp() {

    }
    public void destroyApp(boolean unconditional) {
        
    }
    public void exit() {
        destroyApp(false);
        notifyDestroyed();
    }
    public GameView getGameView() {
        return touchGameView;
    }
    public void showSettings() {
        display.setCurrent(settings);
    }
}