📄 softbutton.java
字号:
package opusmicro.demos.gray;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
public class SoftButton {
protected Command leftCommand;
protected Command rightCommand;
protected CommandListener listener;
protected Displayable displayable;
private int commandBackgroundColor = 0x7FFFD4;
public SoftButton() {
}
public void init(Displayable displayable, Font font,Command leftCommand,Command rightCommand){
this.displayable = displayable;
if(leftCommand!=null){
this.setLeftCommand(leftCommand);
}
if(rightCommand!=null){
this.setRightCommand(rightCommand);
}
}
public void keyPressed(int keyCode){
if ( keyCode == -6) {
if ( leftCommand != null && listener != null) {
listener.commandAction(leftCommand, displayable);
}
}
else if ( keyCode == -7) {
if ( rightCommand != null && listener != null) {
listener.commandAction(rightCommand, displayable);
}
}
}
public void paint(Graphics g){
if(leftCommand!=null){
g.setColor(commandBackgroundColor);
g.fillRect(1, displayable.getHeight()-21, 40, 20);
paintCommand(g,leftCommand,true);
}
if(rightCommand!=null){
g.setColor(commandBackgroundColor);
g.fillRect(displayable.getWidth()-40, displayable.getHeight()-21, 40, 20);
paintCommand(g,rightCommand,false);
}
}
private void paintCommand(Graphics g, Command command,boolean enableLeft){
g.setColor(0x242424);
if(enableLeft){
g.drawString(command.getLabel(), 2, displayable.getHeight()-20, 0);
}
// g.setColor(0x242424);
if(!enableLeft){
g.drawString(command.getLabel(), displayable.getWidth()-39, displayable.getHeight()-20, 0);
}
}
public Command getLeftCommand() {
return leftCommand;
}
public void setLeftCommand(Command leftCommand) {
this.leftCommand = leftCommand;
}
public Command getRightCommand() {
return rightCommand;
}
public void setRightCommand(Command rightCommand) {
this.rightCommand = rightCommand;
}
public CommandListener getCommandListener() {
return listener;
}
public void setCommandListener(CommandListener listener) {
this.listener = listener;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -