×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    101

    Reading screenHeight() gives wrong number

    Hi,

    I'm trying to make a canvas app adapt to screen size of the device its running on, but I just encountered that on my Nokia N95 with a resolution of 240x320 the width is ok but as height I only get 256 instead of 320.

    How to come, that I get this apparently wrong number?

    Cheers
    Simon

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

    Thumbs up Re: Reading screenHeight() gives wrong number

    Hey,
    Is should not be happen,have you check this by drawing the same on screen??
    please check whether you have set the setFullscreenMode(true),

    on emulator it is giving the exact value what you expect..s-40 3rd ed.check this out...

    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    /*
    * Canvas1.java
    *
    * Created on January 9, 2009, 6:16 PM
    *
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    */

    /**
    *
    * @author rajiv
    */
    public class Canvas1 extends Canvas
    {

    /** Creates a new instance of Canvas1 */
    public Canvas1()
    {
    setFullScreenMode(true);
    }

    protected void paint(Graphics graphics)
    {
    graphics.setColor(0);
    graphics.fillRect(0,0,getWidth(),getHeight());
    graphics.setColor(255,255,255);
    graphics.drawString("w = "+getWidth(),10,20,0);
    graphics.drawString("h = "+getHeight(),10,40,0);
    }
    }
    ////////////////////////////////////////////////////////////////////////////
    /*
    * Midlet.java
    *
    * Created on January 9, 2009, 6:13 PM
    */

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    /**
    *
    * @author rajiv
    * @version
    */
    public class Midlet extends MIDlet
    {
    public void startApp()
    {

    Display.getDisplay(this).setCurrent(new Canvas1());
    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
    }
    }

    have this code and test,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    101

    Re: Reading screenHeight() gives wrong number

    Yes, in my code fullScreen is set true.

    I just tried it on the S60 3rd emulator which has a res of 352x416 and again I get the correct width but this time 288 as height.

    Very strange...

  4. #4
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Reading screenHeight() gives wrong number

    Draw a cross by drawing 2 lines:
    1. (0, 0) to (Width - 1, Height - 1)
    2. (Width - 1, 0) to (0, Height - 1)
    And check where "X" is drawn. This will help you diagnose problem.
    Post the code here and if possible photo of phone screen with "X" so that people here can also diagnose the problem.

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

    Re: Reading screenHeight() gives wrong number

    When do you get the screen-height?

    When you do "setFullScreenMode(true)", not all devices change screen size immediately. Use the sizeChanged() event, or check the height in paint().

  6. #6
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    101

    Re: Reading screenHeight() gives wrong number

    Thanks for these tips. I'll try them out when I'm back at work after the weekend.

  7. #7
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    101

    Re: Reading screenHeight() gives wrong number

    Problem seems to be solved. I put the lines to read the display size a few lines further behind the setFullscreen command and now it gives me the correct numbers. I hope it stays this ways.

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

    Re: Reading screenHeight() gives wrong number

    It won't. It might work on your phone, but it will have the same old problem on other devices.

  9. #9
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Reading screenHeight() gives wrong number

    Quote Originally Posted by grahamhughes View Post
    When do you get the screen-height?

    When you do "setFullScreenMode(true)", not all devices change screen size immediately. Use the sizeChanged() event, or check the height in paint().
    This is correct. Why don't you do this instead of checking display size a few lines further behind the setFullscreen command?

Similar Threads

  1. Replies: 31
    Last Post: 2008-02-13, 16:45
  2. Can I test SMS receiver on the phone without port number?
    By brighteyes in forum Mobile Java General
    Replies: 10
    Last Post: 2007-11-26, 23:38
  3. Accessing IMSI number and Reading SMS
    By nvkr411 in forum Mobile Java General
    Replies: 1
    Last Post: 2004-11-11, 11:44
  4. encoding message centre number
    By udy1971 in forum General Messaging
    Replies: 3
    Last Post: 2002-10-24, 07:38

Posting Permissions

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