Thursday, February 25, 2010

J2me source code to find the screen size to work the application in different screen size

import com.sun.lwuit.Display;

/**
* This class enumerates the different phone resolution categories.
* Note that enums are not supported in source 1.3.
* @author Sirajuddin
*/

public abstract class PhoneDisplay {

public static int LOWRES = 0;
public static int MEDRES = 1;
public static int HIGHRES = 2;

public static int getCategory(Display display)
{
int width = display.getDisplayWidth();
int height = display.getDisplayHeight();

int diagonal = (int) Math.sqrt((width * width) + (height * height));

if(diagonal < 205)
return LOWRES;

return HIGHRES;
}
};