×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    14

    Displaying a logo before start of application

    Hi,

    I want to display a logo for about 5 seconds before a form in the application is created. The code I have written is as follows:
    Code:
    import java.io.IOException;
    import java.util.Timer;
    import java.util.TimerTask;
    
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    
    /*this is the j2me class for showing a logo before the main program starts.
     * The canvas must init with a string containing location of the resource and a timer indicating duration.
     * The canvas should call paint and repaint only as long as the timer runs.
     */
    
    public class timedCanvas /*extends Canvas*/ {
    
    	private String imageURL;
    	private int time2Display;    //the no. of seconds the image needs to be displayed.
    	private myCanvas canvas;
    	private Timer tm;
    	private myTimerTask tt;
    	
    	public timedCanvas(String str, int time) {
    		imageURL = str;
    		time2Display = time;
    		
    		canvas = new myCanvas(imageURL);
    		
    		System.out.println("Getting into creating canvas object.");
    		tt = new myTimerTask(canvas);
    		System.out.println("Canvas created. Moving into creating timer task object.");
    		tm.schedule(tt, 0, time2Display);
    	}
    }
    
    class myCanvas extends Canvas {
    	
    	private Image img;
    	private Graphics g;
    	
    	public myCanvas(String str) {
    		try {
    			img = Image.createImage(str);
    			System.out.println("Creating an image at url:" + str);
    			g = img.getGraphics();
    			System.out.println("Got graphics.");
    		} catch (IOException e) {
    			System.out.println("Caught an exception in image creation.");
    			e.printStackTrace();
    		}
    		System.out.println("Created image. Now trying to paint.");
    	}
    
    	protected void paint(Graphics g) {
    		// TODO Auto-generated method stub
    		System.out.println("Inside paint method.");
    		g.setColor(0, 0, 0);
    		g.fillRect(0, 0, getWidth(), getHeight());
    		g.drawImage(img, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
    	}
    }
    
    class myTimerTask extends TimerTask {
    
    	private myCanvas canvas;
    	
    	public myTimerTask(myCanvas canvas) {
    		this.canvas = canvas;
    		System.out.println("Initialized canvas.");
    	}
    	
    	public void run() {
    		// TODO Auto-generated method stub.
    		canvas.repaint();
    	}
    }
    I call the above piece of code as follows:
    Code:
    public void form1() {
       timedCanvas = new timedCanvas("/scfloral.png", 5000);
    }
    Every time the program runs, I end up with a Illegal State Exception. I am new to Java/J2ME and would welcome help/critiques on the code.

    Thanks,
    Sriram

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Displaying a logo before start of application

    you never actually _display_ your canvas. you need to call Display.getDisplay(myMIDlet).setCurrent(myCanvas). (and pleeeeeease name your classes with a capital first letter)

  3. #3
    Registered User
    Join Date
    Sep 2010
    Location
    India
    Posts
    61

    Re: Displaying a logo before start of application

    if you are using visual midlet provided by netbeans then you just need to use
    splash screen component and set its time state as 5 sec

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Displaying a logo before start of application

    1. I am not able to find the MIDlet in your code.
    2. I think that you need to just create the Canvas and timer task class with the MIDlet. You just create the Canvas instance inside the MIDlet and set the same as the current displayable and schedule the timer.

    Please try to debug the code and let us know the exact line which is throwing the exception.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Application Start at Start up using Push registry
    By s.abulkalamazad in forum Mobile Java General
    Replies: 1
    Last Post: 2010-04-22, 08:28
  2. Start a exe on J2ME application start up
    By sandeepkumar03 in forum Mobile Java General
    Replies: 2
    Last Post: 2009-02-05, 23:53
  3. Replies: 0
    Last Post: 2004-08-22, 10:43
  4. How to put my logo when the program start?
    By sbhanry in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2003-03-11, 14:49
  5. Screen Saver and Start Up logo
    By bamboe in forum Smart Messaging
    Replies: 1
    Last Post: 2002-09-24, 07:34

Posting Permissions

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