Hi does anyone know how to make a GameCanvas visible; This is my code:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;

public class TankCanvas extends GameCanvas implements Runnable {
    private Fish fish;
    private boolean start;

    private LayerManager layerManager;
    private Layer layer;
    private int width,height;
    private double px,py;


    public TankCanvas(){
        super(true);
        layerManager=new LayerManager();
        width=this.getWidth();
        height=this.getHeight();
        try{
            fishSprite=this.getFishSprite();
        }catch(IOException e){System.out.println(e);}
        layerManager.setViewWindow(0, 0,width , height);
        System.out.println("The height: "+height+" and the width:
"+width);
        createDefaultTank();
        System.out.println("end of constructor");

    }

    /**
     * create background
     */
    private void createDefaultTank(){
        try{
            this.water=this.getWater();
            water.setPosition(0, 0);
            water.setVisible(true);
            layerManager.append(water);
            System.out.println(layerManager.getSize());
            layer=layerManager.getLayerAt(0);
            layer.setVisible(true);
        }catch(IOException e){System.out.println("IO error");}
    }



    public void start(){
        start=true;
        Thread thread=new Thread(this);
        thread.start();
    }
    public void stop(){
        start=false;
    }

    public Image getPlatform_tiles() throws java.io.IOException
{
        if (platform_tiles == null) {
            // write pre-init user code here
            platform_tiles = Image.createImage("/
platform_tiles.png");
        }
        // write post-init user code here
        return this.platform_tiles;
    }


    public Sprite getFishSprite() throws java.io.IOException
{
        if (fishSprite == null) {
            // write pre-init user code here
            fishSprite = new Sprite(getPlatform_tiles(), 16,
16);
            fishSprite.setFrameSequence
(fishSpriteseq001);
            // write post-init user code here
        }
        return fishSprite;
    }


    public TiledLayer getWater() throws java.io.IOException
{
        create tiled layer here......
    }


    public TiledLayer getObstacle() throws java.io.IOException
{
       create tiled layer here....
    }




    public TiledLayer getPredator() throws java.io.IOException
{
       create tiled layer here.....
    }




    public void render(Graphics g){
       try{
           this.fishSprite=this.getFishSprite();
           System.out.println("sprite position: X :
"+fishSprite.getRefPixelX()+" Y: "+fishSprite.getRefPixelY());
            this.fishSprite.setPosition((int)fish.getPoint().getPx(),
(int) fish.getPoint().getPy());
       }catch(IOException e){System.out.println("value of the sprite:
"+fishSprite.toString()+e);}
            fish.move(fish.getPoint().getPx(), fish.getPoint().getPy
());
    }
    public void run(){
        while(!this.start){
            Graphics g=this.getGraphics();
            this.render(g);

            this.flushGraphics();
            try{
                Thread.sleep(100);
            }catch(InterruptedException e){System.out.println(e);}
        }
    }

  }

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.netbeans.microedition.lcdui.SplashScreen;

public class Tank extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    private TankCanvas tankCanvas=null;
    private Display display;
    private Alert alert;

    public Tank() {
        //initialize everything
        alert=new Alert("not showing");
    }

public void startMIDlet () {
        // write pre-action user code here
       if(tankCanvas==null){
           //create a new canvas
           tankCanvas=new TankCanvas();
           tankCanvas.start();
       }
        System.out.println("Tank: is display visible:
"+tankCanvas.isShown());
        this.display=Display.getDisplay(this);
        display.setCurrent(tankCanvas);
switchDisplayable (null, getSplashScreen ());
        // write post-action user code here
this.switchDisplayable(null, tankCanvas);
}
public void switchDisplayable (Alert alert, Displayable
nextDisplayable) {
        // write pre-switch user code here
Display display = getDisplay ();
if (alert == null) {
display.setCurrent (nextDisplayable);
} else {
display.setCurrent (alert, nextDisplayable);
}
        // write post-switch user code here
}

public void commandAction (Command command, Displayable displayable) {
 // write pre-action user code here
if (displayable == splashScreen) {
if (command == SplashScreen.DISMISS_COMMAND) {
 // write pre-action user code here
exitMIDlet ();
 // write post-action user code here
}
}

    public void exitMIDlet() {
       tankCanvas.stop();
    }

    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            startMIDlet ();
        }
        midletPaused = false;
    }

    public void pauseApp() {
        midletPaused = true;
    }

    public void destroyApp(boolean unconditional) {
        tankCanvas.stop();
    }

   public Display geDisplay(){
        some code to create new display

   }

}

Thank you i would appreciate any help thank you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to