×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    59

    Which is faster / better ?

    Hello,

    I was wondering, let's say we have a complex menu, something like:
    Code:
    main menu - menu1, menu2, menu3, menu4
    menu1 - menu11, menu12, menu1,3
    menu2 - menu21, menu22, menu2,3
    ...
    Which of the following options is faster:

    1. Having multiple Canvas objects (one for each menu) and switch between them using setCurrent()
    2. Having one Canvas and repaint it each time the menu changes

    I'm talking about 10-20 menus here

    Thanks,
    Alex

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Which is faster / better ?

    "Better" is a matter of opinion.

    I can tell you that using multiple Canvases is likely to be slower, and on some devices you might see occasional "glitches" as you switch from one to another. Games are generally written to use a single Canvas, as it gives the fastest and smoothest appearance. But it's not necessarily a very "object oriented" approach.

    That said, you can make it completely OO, in the way that LWUIT does. It uses a single Canvas, always displayed, and delegates the paint() event to other objects as needed. So, you end up with something like:

    Code:
    public interface Paintable {
        public void paint(Graphics g);
    }
    
    public class AlwaysDisplayed extends Canvas {
        private Paintable current;
    
        public void setCurrent(Paintable p) {
            current = p;
        }
    
        protected void paint(Graphics g) {
            if (current != null) {
                // delegate event
                current.paint(g);
            } else {
                // some default behaviour (like, paint a loading screen)
            }
        }
    }
    You can delegate other events in the same way.

    Graham.

Similar Threads

  1. GCCE complied code faster than RVCT compiled code
    By maniish.kesarkar in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2009-11-29, 08:18
  2. Which one is faster? Receiving SMS from SMSC or auto run application?
    By charles_happysunny in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-02-21, 01:01
  3. Faster: RDbNamedDatabase or RFile?
    By sarae in forum Symbian
    Replies: 1
    Last Post: 2008-03-07, 17:03
  4. createImage OR fillRect what is faster ?
    By waxattack in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2004-10-19, 07:39
  5. Is it possible to make a MIDlet close faster?
    By Krunoi in forum Mobile Java General
    Replies: 0
    Last Post: 2003-10-12, 19:32

Posting Permissions

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