×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    42

    how to implement a timer with images

    hi
    i want to know that how can we call a timer so that i could change image every 4sec in my application.i have to call 3to4 images one after the other in the midlet after the images have been changed they have to be repeated again any sample code could be helpful
    thanku

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: how to implement a timer with images

    Hi,

    Please see this article for information on using timers. It's a pretty basic example and all you have to do is add your code for displaying the images. It should work.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    42

    Re: how to implement a timer with images

    but i want diffent image every 4seconds

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    42

    Re: how to implement a timer with images

    *****************************

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    42

    Re: how to implement a timer with images

    but i want a different image after every 4sec
    thanku

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: how to implement a timer with images

    Well here's an example which displays one of two images every 4 seconds. All you have to do is adapt it to your needs:
    Code:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import java.util.Timer;
    import java.util.TimerTask;
    
    public class MyMIDlet extends MIDlet implements CommandListener {
        
        public Display display;
        public Command exit;
        public MyCanvas cv;
        public MyTask ts;
        public Image[] imgList=new Image[2];
        
        public void commandAction(Command c, Displayable d) {
            if(c==exit)
                ts.cancel();
                notifyDestroyed();
        }
        
        public void startApp() {
            display=Display.getDisplay(this);
            exit=new Command("Exit", Command.EXIT, 0);
            cv=new MyCanvas();
            cv.addCommand(exit);
            cv.setCommandListener(this);
            display.setCurrent(cv);
            //Add the images into an array to choose which image is up for drawing easily
            try {
                    Image img1=Image.createImage("src/picture1.jpg");
                    Image img2=Image.createImage("src/picture2.gif");
                    imgList[0]=img1;
                    imgList[1]=img2;
            }
            catch(Exception e) {
                
            }
            //Set the timed task to draw the next image every 4000 milliseconds
            Timer crono = new Timer();
            ts=new MyTask();
            crono.schedule(ts, 0, 4000);
        }
        
        public void pauseApp() {
            
        }
        
        public void destroyApp(boolean unconditional) {
            
        }
        
    
    
    class MyCanvas extends Canvas {
        
        int i=0;
        
        public void paint(Graphics g) {
            //Display the image and increase the index in order to know which image is next
            g.drawImage(imgList[i], 0, 0, Graphics.TOP|Graphics.LEFT);
            i++;
            if(i==2)
                i=0;
        }
        
    }
    
    class MyTask extends TimerTask {
        
        public void run() {
            //Simply "refresh" the canvas
            cv.repaint();
      }
     
    }
    
    }

  7. #7
    Registered User
    Join Date
    Jan 2008
    Location
    Pune
    Posts
    24

    Re: how to implement a timer with images

    Hi praran910,

    Try with these steps:
    1. create a Image array, fill it with images how much u want.
    2. display First Image.
    3. Start Timer.
    4. after every four second call repaint() of canvas class or display the form with new Image object by increamented counter by 1.

    and the code given by bogdan.galiceanu is very usefull.

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    42

    Re: how to implement a timer with images

    i want it to be done in midlet but not in canvas is there any possibility there
    Thank u

  9. #9
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    254

    Re: how to implement a timer with images

    let us take some points
    1)Does a midlet contain API to hold images
    i have a suggestion if u wish u can have a look
    1)Take a Canvas or a Form and use it in the midlet now u can show the image in the Form or Canvas.
    2)Run your timer by using a Timer class and TimerTask
    these have thread running for performing the task .. then in Canvas
    repaint();
    After setting the display
    for form reset the display


    i feel this will fulfill ur need

    regards
    Arun Gupta

Similar Threads

  1. When can you set the screensaver's Refresh Timer Value?
    By azhrei in forum Symbian Tools & SDKs
    Replies: 6
    Last Post: 2008-08-23, 10:12
  2. Crash with multiple ao_timer
    By noreli in forum Symbian
    Replies: 2
    Last Post: 2007-11-01, 06:18
  3. popup control for timer using active objects
    By nishantghai in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-04-16, 07:31
  4. How to implement Timer
    By PankajNeve in forum Symbian
    Replies: 2
    Last Post: 2006-05-03, 11:30
  5. Timer delay between playbacks???
    By lalitsharma in forum Symbian
    Replies: 3
    Last Post: 2005-09-09, 11:45

Posting Permissions

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