×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    going back and forth between form & full screen canvas

    Experts...Please take a look at this code. This snippet is the full screen canvas which display an image. I would like to press keycode -7 and go back to the "form" where it came from. The code displays the image OK, but does not want to go back. There are no errors or crashes, just as if keypress event never happens.. Any ideas, what I am doing wrong !!!

    public class iCanvas extends FullCanvas {

    trackGolf tg; // My midlet, calls this full screen canvas
    Image image;

    iCanvas(trackGolf aThis) {

    }

    protected void paint(Graphics g) {
    g.drawImage(image, 0, 0, 0);
    }

    public void createImage(Image s) {
    image = s;
    }
    public void keypressed(int keycode) {
    tg = new trackGolf();
    if (keycode == -7) {
    tg.switchDisplayable(null, tg.getForm());
    }
    }

    }

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: going back and forth between form & full screen canvas

    What are you doing in the switchDisplayable() method?

    Also if the trackGolf class is extending MIDlet class, you should not try to use new with it...

    Hartti

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    Re: going back and forth between form & full screen canvas

    Quote Originally Posted by hartti View Post
    What are you doing in the switchDisplayable() method?

    Also if the trackGolf class is extending MIDlet class, you should not try to use new with it...

    Hartti
    Here is the code for switchDisplayable...

    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
    }

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: going back and forth between form & full screen canvas

    Ok, that seems correct, which brings us to my second point.

    You should not try to create another MIDlet in your MIDlet. Without seeing your code it is hard to say what changes you would need to do, but basically you need to either store the reference to your MIDlet somehow for all the classes (it that is really needed) or then you could pass the reference to your MIDLet class as an parameter to all relevant classes.

    Hartti

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    Re: going back and forth between form & full screen canvas

    I tried following, removing the "new" from trackGolf, but still the same problem.

    public class iCanvas extends FullCanvas {

    Image image;
    Display disp;
    Displayable form;
    trackGolf tg;

    iCanvas(trackGolf aThis) {
    disp = aThis.getDisplay();
    form = aThis.getForm();
    }

    protected void paint(Graphics g) {
    g.drawImage(image, 0, 0, 0);
    }

    public void createImage(Image s) {
    image = s;
    }
    public void keypressed(int keycode) {
    if (keycode == -7) {
    tg.switchDisplayable(null, form);
    }
    }

  6. #6
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: going back and forth between form & full screen canvas

    Now the variable tg is null in the keypressed method. - Please read my answer above

    Also the method should be keyPressed not keypressed.
    http://developers.sun.com/mobility/midp/articles/event/

    Hartti

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    Re: going back and forth between form & full screen canvas

    OK Problem solved.. I think I got on the track because of typo that you finally caught keyPressed instead of keypressed. That in combination with the my original midlet was never assigned a value (a null, as you pointed out)... Many thanks for your help... Following code works...

    public class iCanvas extends FullCanvas {

    Image image;
    Display disp;
    Displayable form;
    trackGolf tg;

    iCanvas(trackGolf aThis) {
    disp = aThis.getDisplay();
    form = aThis.getForm();
    tg = aThis;
    }

    protected void paint(Graphics g) {
    g.drawImage(image, 0, 0, 0);
    }

    public void createImage(Image s) {
    image = s;
    }
    public void keyPressed(int keycode) {
    if (keycode == -7) {
    tg.switchDisplayable(null, form);
    }
    }

Posting Permissions

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