?? softkeybar.java
字號:
package com.jmobilecore.ui.core;
import javax.microedition.lcdui.Graphics;
/**
* The <code>SoftKeyBar</code> is special <code>Component</code> which represents
* bottom line of the phone screen with names of soft keys.
* This class contains set of methods that supports insertion/delition of soft keys
* and execution of associated actions when softkey is pressed
*
* @author Greg Gridin
*/
public class SoftKeyBar extends Component {
/**
* The left positioned softkey
*/
protected SoftKey leftSoftKey;
/**
* The center positioned softkey
*/
protected SoftKey centerSoftKey;
/**
* The right positioned softkey
*/
protected SoftKey rightSoftKey;
/**
* Constructs a new softkey bar
*/
public SoftKeyBar() {
foreground = Style.SOFTKEYBAR_TEXT_COLOR;
background = Style.SOFTKEYBAR_BACKGROUND_COLOR;
setFont(Style.SOFTKEY_FONT);
}
/**
* Sets softkey to the softkey bar
* If new soft key is <code>null</code> then action is equivalent to <code>removeSoftKey</code>
* from specified position
* @param softKey new soft key
* @param position the position of the key,
* @see com.jmobilecore.ui.core.SoftKey
* @see #removeSoftKey(int)
*/
public void setSoftKey(SoftKey softKey, int position) {
if (position == SoftKey.LEFT) {
leftSoftKey = softKey;
} else if (position == SoftKey.CENTER) {
centerSoftKey = softKey;
} else if (position == SoftKey.RIGHT) {
rightSoftKey = softKey;
}
}
/**
* Removes softkey from the softkey bar
* @param position the position of the key,
* if there is no key in specified position then does nothing
* @see com.jmobilecore.ui.core.SoftKey
*/
public void removeSoftKey(int position) {
if (position == SoftKey.LEFT) {
leftSoftKey = null;
} else if (position == SoftKey.CENTER) {
centerSoftKey = null;
} else if (position == SoftKey.RIGHT) {
rightSoftKey = null;
}
}
/**
* Paints the cursor for this component
* @param g Graphics object
*/
public void paint(Graphics g) {
g.setColor(background);
g.fillRect(0, ScreenCanvas.HEIGHT - this.height, ScreenCanvas.WIDTH, this.height);
g.setColor(foreground);
g.setFont(font);
if (leftSoftKey != null) {
g.drawString(leftSoftKey.label, Style.H_GAP, ScreenCanvas.HEIGHT,
Graphics.BOTTOM | Graphics.LEFT);
}
if (centerSoftKey != null) {
g.drawString(centerSoftKey.label, ScreenCanvas.WIDTH / 2, ScreenCanvas.HEIGHT,
Graphics.BOTTOM | Graphics.HCENTER);
}
if (rightSoftKey != null) {
g.drawString(rightSoftKey.label, ScreenCanvas.WIDTH - Style.H_GAP, ScreenCanvas.HEIGHT,
Graphics.BOTTOM | Graphics.RIGHT);
}
}
/**
* Responds to a key press.
* @param keyCode The code for the key that was pressed.
* @return <code>true</code> if the key was successfully processed, <code>false</code> otherwise
*/
protected boolean keyPressed(int keyCode) {
if (keyCode == SoftKey.LEFT && leftSoftKey != null) {
leftSoftKey.performAction();
return true;
} else if (keyCode == SoftKey.CENTER && centerSoftKey != null) {
centerSoftKey.performAction();
return true;
} else if (keyCode == SoftKey.RIGHT && rightSoftKey != null) {
rightSoftKey.performAction();
return true;
}
return false;
}
/**
* Default destructor. Helps VM to perform garbage collection
*/
public void destructor() {
leftSoftKey = centerSoftKey = rightSoftKey = null;
}
} // class SoftKeyBar
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -