×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    12

    cannot jump from canvas back to form

    I create a form:

    public class CanvasBasics extends MIDlet implements CommandListener
    {
    private Display display; // The display
    public Form fmMain;
    private TextCanvas canvas; // Canvas to display text
    private Command cmdMenu;
    public CanvasBasics()
    {

    fmMain = new Form("name");
    cmdMenu = new Command("Meniu", Command.ITEM, 1);
    fmMain.addCommand(cmdMenu);
    fmMain.setCommandListener(this);
    canvas = new TextCanvas(this);
    }
    public void commandAction(Command c, Displayable s)
    {
    if (c == cmdMenu) {display.setCurrent(canvas);}

    I also create a canvas :

    class TextCanvas extends Canvas implements CommandListener
    {
    private Display display;
    private Command cmExit;
    // private Form fmMain;
    private CanvasBasics midlet;
    // private int integ = 2;
    private Timer tm; // The Timer
    private DownloadTimer tt; // The task to run
    public TextCanvas(CanvasBasics midlet)
    {
    cmExit = new Command("Exit", Command.EXIT, 1);
    addCommand(cmExit);
    setCommandListener(this);
    }

    I want to go back to fmMain. I do this :

    public void commandAction(Command c, Displayable d)
    {
    if (c == cmExit) display.setCurrent(midlet.fmMain);

    But midlet says : null pointer.
    How to solve it and be able to get back to fmMain?

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    12
    I have solved it my self, by adding a public function in first class whick is smth like this:

    public void showMain()
    {
    display.setCurrent(fmMain);
    }

    and in canvas class I just use showMain(); whenever I need it.

    :-) sorry for spaming, but someone may will find this useful. Good luck :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×