Question

I am getting following message whenever I try to implement CommandListener. Please let me know what I need do?

Midlet is not abstract and does not override abstract method commandAction(Command,Displayable) in CommandListener

package displaytest;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;


public class Midlet extends MIDlet  implements CommandListener {

  private Display display = null;
  private Form form;

  public void startApp() {
    form = new Form("Hello World");
    String msg = "Hello World!  DisplayTest 12";
    form.addCommand(screen);
    form.addCommand(ok);
    form.append(msg);
    display = Display.getDisplay(this);
    display.setCurrent(form);
  }

  private Command screen, ok;

  public Midlet(){
    form = new Form("Command Form");
    screen = new Command("SCREEN", Command.SCREEN, 1);
    ok = new Command("OK", Command.OK, 4);
  }

  public void pauseApp() {

  }

  public void destroyApp(boolean unconditional) {
    notifyDestroyed();
  }

  public void okCom(){
    Alert ok = new Alert("OK Command", "OK Command Executed!", null, AlertType.INFO);
    ok.setTimeout(5000);
    display.setCurrent(ok, form);  
  }

}
Was it helpful?

Solution

You need to implement the method that interface declares, Check CommandListener you need to implement the method it declares as follows

void commandAction(Command c, Displayable d){
 // your logic
} 

OTHER TIPS

You need to make the class abstract, or override the abstract method commandAction(Command,Displayable).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top