04-13-2009 02:26 AM
Hi team,
I have a following code:
import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*; import net.rim.device.api.system.*; import net.rim.device.api.collection.util.*; import net.rim.device.api.ui.decor.*; import java.util.*; public final class SeedAboutScreen extends MainScreen implements SeedManagerResource { //members --------------------------------------------------
---------------- private static ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME); private static SeedHelpScreen _seedHelpScreen; private VerticalFieldManager _manager; public SeedAboutScreen() { super(); _manager = (VerticalFieldManager)getMainManager(); BitmapField image_top = new BitmapField(Bitmap.getBitmapResource(_resources.ge tString(IMAGE_TOP)), FIELD_HCENTER | FOCUSABLE); Background image_background = BackgroundFactory.createBitmapBackground(Bitmap.ge tBitmapResource(_resources.getString(IMAGE_BACKGRO UND)), 0, 0, Background.REPEAT_INHERIT); BitmapField image_logo = new BitmapField(Bitmap.getBitmapResource(_resources.ge tString(IMAGE_LOGO)), FIELD_HCENTER | FOCUSABLE); _manager.setBackground(image_background); Font font_title = this.getFont().derive(Font.PLAIN | Font.BOLD); Font font_application = this.getFont().derive(Font.PLAIN, 16); Font font_bold = this.getFont().derive(Font.PLAIN | Font.BOLD, 16); LabelField _titleField = new LabelField(_resources.getString(APPLICATION_TITLE) , FOCUSABLE); LabelField _descriptionField = new LabelField(_resources.getString(APPLICATION_DESCRI PTION), FOCUSABLE); LabelField _versionField = new LabelField("Version: " + _resources.getString(APPLICATION_VERSION), 0, -1, Field.FIELD_RIGHT | FOCUSABLE); _titleField.setFont(font_title); _descriptionField.setFont(font_bold); _versionField.setFont(font_bold); try { _manager.add(image_top); _manager.add(_titleField); _manager.add(new LabelField(" ")); _manager.add(_descriptionField); _manager.add(new SeparatorField()); _manager.add(_versionField); _manager.add(new LabelField(" ")); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } } public boolean onClose() { _seedHelpScreen = new SeedHelpScreen(); UiApplication.getUiApplication().pushScreen(_seedH elpScreen); return true; } public boolean keyChar(char key, int status, int time) { //intercept the ESC key - back out of this screen on its receipt boolean retval = false; switch (key) { case Characters.ESCAPE: onClose(); retval = true; break; } return retval; } private MenuItem _closeItem = new MenuItem(null, 0 , 200000, 10) { public void run() { onClose(); } public String toString() { return "Close"; } }; protected void makeMenu ( Menu menu, int instance ) { menu.add(_closeItem); } }
I need get the width screen for create the following option:
Switch (widthScreenDevice())
case 480:BitmapField image_top = new BitmapField("image 1.png");
case 320:
BitmapField image_top = new BitmapField("image 2.png");
...
I don't have idea about this, please help me.
Thanks.
Solved! Go to Solution.
04-13-2009 02:28 AM
Display.getWidth() will get you the screen width!
Thanks!
04-13-2009 02:37 AM
Thanks, but How can insert this function "Display.getWidth()" in my code? I have tested, but, I can't integrated.
04-13-2009 02:45 AM
04-13-2009 02:52 AM
Sorry, I don't undertand. Would you explain again?
Thanks
04-13-2009 02:53 AM
In your code, instead of widthScreenDevice(), add Display.getWidth()
Thanks!
04-13-2009 04:13 AM
Hi,
Take 2 public static variables say deviceWidth and deviceHeight and initialize these variables with
deviceWidth = Display.getWidth() and deviceHeight = Display.getHeight()
Initialize these variables inside the constructor of the class which contains main() and then use these variables in your application.