I've been coding a tamagotchi app for the Nokia N95 with MIDP 2.0. I'd been working on the Sun emulator until last night when I copied it to the phone. Running it on the phone was a bit deperessing because all the nice images in my custom status screen overlapped. It seemed slightly odd as I'd gone out of my way to ensure I calculated the height and width of all the bits and used them to get an overall minimum and preferred height e.g.
Class MyItem extends CustomItem {
    byte height;
    byte width;
    public MyItem() {
        this.width=part1.getPreferredWidth();
        this.width+=part2.getPreferredWidth();
         this.height=Math.max(part1.getPreferredHeight(), part2getPreferredHeight());
    }
    protected int getMinContentHeight() {
        return this.height;
    }
    protected int getMinContentWidth() {
        return this.width;
    }
    protected int getPrefContentHeight(int width) {
        return this.height;
    }
    protected int getPrefContentWidth(int height) {
        return this.width;
    }
}
However, whilst this works in the emulator, it turns out I need another line to make it work on the phone. Adding the following:
        this.setPreferredSize(this.width, this.height);
at the end of my constructor fixed my problem and now it all looks pretty great! :)
 
 
 

I'm glad it worked in the end! Sounds like complicated stuff.
ReplyDelete