?? softbutton.java
字號:
/********************************************************************
*
* 版權說明,此程序僅供學習參考。不能用于商業
*
********************************************************************/
package org.pook.ui;
import javax.microedition.lcdui.Graphics;
import org.pook.ui.core.Platform;
import org.pook.ui.event.CommandListener;
/**
* <b>類名:SoftButton.java</b> </br> 編寫日期: 2006-9-14 <br/> 程序功能描述?? <br/> Demo:
* <br/> Bug: <br/>
*
* 程序變更日期 ??<br/> 變更作??? ??<br/> 變更說明 ??<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public class SoftButton extends Part {
/** 軟鍵 * */
private CommandListener commandListener;
private Command left;
private Command right;
private Command middle;
/**
* 構???固定位置的軟鍵??
*
*/
public SoftButton() {
super(0, Platform.HEIGHT - 20, Platform.WIDTH, Platform.HEIGHT);
}
/**
* 添加????
*
* @param item
*/
public void addCommand(Command cmd) {
if (cmd.type == Command.LEFT)
this.left = cmd;
else if (cmd.type == Command.RIGHT) {
this.right = cmd;
} else if (cmd.type == Command.MIDDLE) {
this.middle = cmd;
}
}
/** 刪除相應的Command */
public void removeCommand(int type) {
if (type == Command.LEFT)
left = null;
else if (type == Command.MIDDLE)
middle = null;
else if (type == Command.RIGHT)
right = null;
}
/**
* 注冊監視??
*/
public void setCommandListener(
CommandListener commandListener) {
this.commandListener = commandListener;
}
public void paint(Graphics g) {
paintCmdsImpl(g);
}
/**
* 繪制cmds
*/
private void paintCmdsImpl(Graphics g) {
fillCmdsClip(g);
paintCmdNames(g);
}
// 填充cmds區域
private void fillCmdsClip(Graphics g) {
if (Platform.HEIGHT - 20 > this.view[HEIGHT]) {
view[Y] = Platform.HEIGHT - 20;
view[HEIGHT] = Platform.HEIGHT;
}
g.setColor(bgColor);
g.fillRect(view[X], view[Y], view[WIDTH], view[HEIGHT]);
g.setColor(0x000000);
//畫條白線
g.drawLine(view[X],view[Y],view[WIDTH],view[Y]);
}
private void paintCmdNames(Graphics g) {
g.setFont(this.font);
g.setColor(fontColor);
if (left != null) {
g.drawString(left.name, 2, view[Y] + 2, Graphics.TOP
| Graphics.LEFT);
}
if (middle != null) {
g.drawString(middle.name, view[WIDTH] / 2, view[Y] + 2,
Graphics.HCENTER | Graphics.TOP);
}
if (right != null) {
g.drawString(right.name, view[WIDTH] - 2, view[Y] + 2, Graphics.TOP
| Graphics.RIGHT);
}
}
/**
* 按鈕的動??
*/
public void onClick(int keyCode) {
if (this.commandListener == null)
return;
if (keyCode == Platform.KEY_SOFT_LEFT && cmdIsExist(left)) {
commandListener.commandAction(left);
} else if (keyCode == Platform.KEY_SOFT_RIGHT && cmdIsExist(right)) {
commandListener.commandAction(right);
} else if (keyCode == Platform.KEY_ENTER) {
if (cmdIsExist(left) && left.priority == Command.FIRST_PRIORITY) {
commandListener.commandAction(left);
return;
}
if (cmdIsExist(right) && right.priority == Command.FIRST_PRIORITY) {
commandListener.commandAction(right);
}
}
}
// 判斷是否存在這個命令,如果為空,或???標題為""則表示不存在
private boolean cmdIsExist(Command cmd) {
if (cmd == null || cmd.equals(""))
return false;
else
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -