MIDP中使用类Display进行用户界面的管理,负责与应用程序管理器进行交互,并且用Displayable的子类(Screen,Canvas)代表可以显示的用户界面.

  Display类
Display代表了系统显示屏幕和输入设备的管理器,用来获取设备属性的方法以及向设备建议应该显示的对象.
Display方法说明(本人较懒,直接复制帮助文档里的方法说明了)

● void callSerially(Runnable r)
Causes the Runnable object r to have its run() method called later, serialized with the event stream, soon after completion of the repaint cycle.

● boolean flashBacklight(int duration)
Requests a flashing effect for the device's backlight.

● int getBestImageHeight(int imageType)
Returns the best image height for a given image type.

● int getBestImageWidth(int imageType)
Returns the best image width for a given image type.

● int getBorderStyle(boolean highlighted)
Returns the stroke style used for border drawing depending on the state of the component (highlighted/non-highlighted).

● int getColor(int colorSpecifier)
Returns one of the colors from the high level user interface color scheme, in the form 0x00RRGGBB based on the colorSpecifier passed in.

● Displayable getCurrent()
Gets the current Displayable object for this MIDlet.

● static Display getDisplay(MIDlet m)
Gets the Display object that is unique to this MIDlet.

● boolean isColor()
Gets information about color support of the device.

● int numAlphaLevels()
Gets the number of alpha transparency levels supported by this implementation.

● int numColors()
Gets the number of colors (if isColor() is true) or graylevels (if isColor() is false) that can be represented on the device.

● void setCurrent(Alert alert, Displayable nextDisplayable)
Requests that this Alert be made current, and that nextDisplayable be made current after the Alert is dismissed.

● void setCurrent(Displayable nextDisplayable)
Requests that a different Displayable object be made visible on the display.

● void setCurrentItem(Item item)
Requests that the Displayable that contains this Item be made current, scrolls the Displayable so that this Item is visible, and possibly assigns the focus to this Item.

● boolean vibrate(int duration)
Requests operation of the device's vibrator.

事例代码:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class DisplayDemo extends MIDlet{
Display display;
TextBox textBox;
public DisplayDemo(){
display = Display.getDisplay(this);
textBox = new TextBox("Display Demo" , "screen of current" , 50 , 0);
}
protected void startApp(){
display.setCurrent(textBox);
}
protected void pauseApp(){}
protected void destroyApp(boolean b){}
}


Displayable类
在设备显示屏幕上的用户对象就是Display对象,在同一时刻应用程序最多只有一个Displayable对象被显示在屏幕上,通过它可以同用户进行交互.
Displayable类方法说明

● void addCommand(Command cmd)
Adds a command to the Displayable.

● int getHeight()
Gets the height in pixels of the displayable area available to the application.

● Ticker getTicker()
Gets the ticker used by this Displayable.

● String getTitle()
Gets the title of the Displayable.

● int getWidth()
Gets the width in pixels of the displayable area available to the application.

● boolean isShown()
Checks if the Displayable is actually visible on the display.

● void removeCommand(Command cmd)
Removes a command from the Displayable.

● void setCommandListener(CommandListener l)
Sets a listener for Commands to this Displayable, replacing any previous CommandListener.

● void setTicker(Ticker ticker)
Sets a ticker for use with this Displayable, replacing any previous ticker.

● void setTitle(String s)
Sets the title of the Displayable.

● protected void sizeChanged(int w, int h)
The implementation calls this method when the available area of the Displayable has been changed.

Displayable类是一个抽象类,它有两个直接子类,这两个子类都可以作为参数传递给Display.setCurrent(Displayable nextDisplayable).
● Canvas类: 低级界面API,允许应用程序进行图形处理和输入处理的低层对象.
● Screen类: 高级界面API,封装了完整的用户界面组件.
任何MIDP应用程序都可以将Screen和Canvas整合来展示一个集成后的应用程序接口,例如,在一个游戏中,List和Form可以被用来选择或者配置游戏选项,而Canvas可以用于交互式的游戏界面.

posted on 2013-03-06 12:57  爱哎唉  阅读(177)  评论(0)    收藏  举报