Ê×Ò³ Ê«´Ê ×Öµä °å±¨ ¾ä×Ó ÃûÑÔ ÓÑ´ð ÀøÖ¾ ѧУ ÍøÕ¾µØͼ
µ±Ç°Î»ÖÃ: Ê×Ò³ > ½Ì³ÌƵµÀ > Òƶ¯¿ª·¢ > BlackBerry >

BlackBerryϵͳUIѧϰһ

2012-09-22 
BlackBerryϵͳUIѧϰ1ÏÈ¿´¸öÀý×Ópackage com.hoocyimport net.rim.device.api.system.Bitmapimport net

BlackBerryϵͳUIѧϰ1

ÏÈ¿´¸öÀý×Ó

package com.hoocy;import net.rim.device.api.system.Bitmap;import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;public class UserInterface extends UiApplication {public static void main(String[] args) {UserInterface theApp = new UserInterface();theApp.enterEventDispatcher();}public UserInterface() {pushScreen(new UserInterfaceScreen());}}final class UserInterfaceScreen extends MainScreen {// ˮƽ²¼¾Ö¹ÜÀíÆ÷HorizontalFieldManager _fieldManagerTop;// ´¹Ö±²¼¾Ö¹ÜÀíÆ÷VerticalFieldManager _fieldManagerMiddle;HorizontalFieldManager _fieldManagerBottom;//BitmapField _bitmap;Bitmap _canadaImage, _ukImage, _usImage;LabelField _label;BasicEditField _input;String _canadaCapital, _ukCapital, _usCapital, _capital;int displayed = 0;public UserInterfaceScreen() {super();LabelField title = new LabelField("User Interface Sample",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);setTitle(title);_fieldManagerTop = new HorizontalFieldManager();_fieldManagerMiddle = new VerticalFieldManager();_fieldManagerBottom = new HorizontalFieldManager();add(_fieldManagerTop);add(new SeparatorField());add(_fieldManagerMiddle);add(new SeparatorField());add(_fieldManagerBottom);_canadaImage = Bitmap.getBitmapResource("canada.png");_ukImage = Bitmap.getBitmapResource("uk.png");_usImage = Bitmap.getBitmapResource("us.png");_bitmap = new BitmapField();_bitmap.setBitmap(_canadaImage);_fieldManagerTop.add(_bitmap);_canadaCapital = "Ottawa";_ukCapital = "London";_usCapital = "Washington";_capital = _canadaCapital;_label = new LabelField("Please press a button!");_input = new BasicEditField("Capital (can be changed): ", _capital);_fieldManagerMiddle.add(_label);_fieldManagerMiddle.add(_input);FieldChangeListener listenerCanada = new FieldChangeListener() {public void fieldChanged(Field field, int context) {_bitmap.setBitmap(_canadaImage);_input.setText(_canadaCapital);displayed = 0;}};FieldChangeListener listenerUK = new FieldChangeListener() {public void fieldChanged(Field field, int context) {_bitmap.setBitmap(_ukImage);_input.setText(_ukCapital);displayed = 1;}};FieldChangeListener listenerUS = new FieldChangeListener() {public void fieldChanged(Field field, int context) {_bitmap.setBitmap(_usImage);_input.setText(_usCapital);displayed = 2;}};ButtonField canadaButton = new ButtonField("Canada");ButtonField ukButton = new ButtonField(" UK ");ButtonField usButton = new ButtonField(" USA ");//ÉèÖÃʼþ¸ø²»Í¬µÄ°´Å¥canadaButton.setChangeListener(listenerCanada);ukButton.setChangeListener(listenerUK);usButton.setChangeListener(listenerUS);_fieldManagerBottom.add(canadaButton);_fieldManagerBottom.add(ukButton);_fieldManagerBottom.add(usButton);}// Ôö¼ÓÖ÷²Ëµ¥Ö»ÐèÒª¸´Ð´·½·¨¼´¿Éprotected void makeMenu(Menu menu, int instance) {menu.add(_changeCapital);menu.add(_close);}// ²Ëµ¥¶ÔÏó 1private MenuItem _changeCapital = new MenuItem("Change Capital", 110, 10) {public void run() {if (displayed == 0)_canadaCapital = _input.getText();else if (displayed == 1)_ukCapital = _input.getText();else if (displayed == 2)_usCapital = _input.getText();}};// ²Ëµ¥¶ÔÏó 2private MenuItem _close = new MenuItem("Close", 110, 10) {public void run() {onClose();}};//¹Ø±Õʼþpublic boolean onClose() {Dialog.alert("Goodbye!");System.exit(0);return true;}}
?

ÈȵãÅÅÐÐ