programming

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

programming

Postby Kup » Thu Sep 27, 2007 11:32 am

Hi again

now the problem is in the code

i've got this 2 files just for example:

/* #### FILE 1 ##### */
Code: Select all
public class Inicio extends MIDlet{
   
   Menu menu = new Menu();
   
   ...
   
   public void startApp (){
       int actuale = menu.ACTUAL;

       if(actuale == 0){
           Display display = Display.getDisplay(this);
           display.setCurrent(menu);
       }else if(actuale == 1){
           System.out.println("SUPOSTO CANVAS");
           //Display display = Display.getDisplay(this);           
           //display.setCurrent(canvas);
       }
   }
   
   ...

}



/* #### FILE 2 ##### */

Code: Select all
public class Menu extends Canvas implements Runnable{

   ...   

   Inicio iniciar = new Inicio();

   ...

   protected void keyPressed(int keyCode) {
        int gameAction = getGameAction( keyCode);
        switch (gameAction) {
                ...
            case FIRE:               
                if(MENU_SELECIONADO == 1) {
                    ACTUAL = 1;
                    iniciar.startApp();
                }
            ...
    }

}


ok that was the code
now the problem, it wont even start the app because i added the
"Inicio iniciar = new Inicio();"
but if i take ir out it works fine, but since i need the interaction between the two i really need that

can anyone exaplain to me why this doesn't work?

thanks:)
Kup
 
Posts: 32
Joined: Wed Sep 26, 2007 3:35 pm
Location: Portugal

Postby DevelopmentTeam » Thu Sep 27, 2007 1:42 pm

/* #### FILE 1 ##### */
Code: Select all
public class Inicio extends MIDlet{
   Menu menu = new Menu(this);
   
   ...
   
   public void startApp (){
       int actuale = menu.ACTUAL;

       if(actuale == 0){
           Display display = Display.getDisplay(this);
           display.setCurrent(menu);
       }else if(actuale == 1){
           System.out.println("SUPOSTO CANVAS");
           //Display display = Display.getDisplay(this);           
           //display.setCurrent(canvas);
       }
   }
   
   ...

   public void someFunction() {
    ///do what you want here
   }
}



/* #### FILE 2 ##### */

Code: Select all
public class Menu extends Canvas implements Runnable{
   ...   

   Inicio iniciar;

   ...

   public Menu(Inicio ini) {
      iniciar = ini;
   }

   protected void keyPressed(int keyCode) {
        int gameAction = getGameAction( keyCode);
        switch (gameAction) {
                ...
            case FIRE:               
                if(MENU_SELECIONADO == 1) {
                    ACTUAL = 1;
                    iniciar.someFunction();
                }
            ...
    }

}



StartApp runs when the midlet is loaded, better use some other public function. Pass the midlet object to the menu class... this will solve the problem..
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Sep 27, 2007 1:44 pm

In the first file dont cunstruct the menu object in the definition itself better do it this way

Code: Select all
   Menu menu;

   public void startApp (){
       menu = new Menu(this);
       int actuale = menu.ACTUAL;
       ...
   }
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby Kup » Thu Sep 27, 2007 1:56 pm

again biiiig thanks ;)
Kup
 
Posts: 32
Joined: Wed Sep 26, 2007 3:35 pm
Location: Portugal

Postby DevelopmentTeam » Thu Sep 27, 2007 2:21 pm

:) no problem... Also wanted to tell you one thing... please keep the title bit relative and relevant to the post. It may be long dont worry... So that someone who is searching for a same doubt can catch it easily... :)
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 1 guest

cron