• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diffrent screens with commandlistener

 
Niklas Junel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problems with the commandlistener, if I put all my screens in the mainclass it works fine. But if I want to clean up my code, e g put diffrent screens in seperate files, I can't get it to work.

Do I have to implement commandlistener in every class?

I tried to setCommandlistener on the seperate class in the mainclass (witch implement commandlistener) but then the mainclass could't handle the event in commandAction.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no. There are ways to create a Controller class that handles all command listening for different screens.

in my MIDlet class I have this code. gameController is an instance variable for the controller. I pass this because I need to have the controller be able to call back here to set the display and form my main menu which is a canvas



Here is the callback method in my MIDlet





We wanted the controller to be a Singleton so we get an instance this way



The controller implement CommandListener and here is my commandAction method



Hope that give you an easy example of how to do that.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic