📄 rectangletest.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class RectangleTest extends MIDlet implements ItemStateListener{
Display display;
MyCanvas myCanvas;
ChoiceGroup setFilled, setRound;
Form form;
public RectangleTest(){
display = Display.getDisplay(this);
myCanvas = new MyCanvas();
form = new Form("选择矩形类型");
setFilled = new ChoiceGroup("Filled", List.EXCLUSIVE);
setRound = new ChoiceGroup("Round", List.EXCLUSIVE);
setFilled.append("FALSE", null);
setFilled.append("TRUE", null);
setRound.append("FALSE", null);
setRound.append("TRUE", null);
form.append(setFilled);
form.append(setRound);
form.setItemStateListener(this);
}
public void startApp(){
display.setCurrent(myCanvas);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void itemStateChanged(Item item){
if(item == setFilled){
int index = setFilled.getSelectedIndex();
myCanvas.isFilled = (index == 0? false: true);
}
else if(item == setRound){
int index = setRound.getSelectedIndex();
myCanvas.isRound = (index == 0? false: true);
}
myCanvas.repaint();
display.setCurrent(myCanvas);
}
class MyCanvas extends Canvas implements CommandListener{
int width;
int height;
int arcWidth;
int arcHeight;
int x, y;
int mode;
boolean isFilled;
boolean isRound;
Command exitCmd;
Command changeCmd;
public MyCanvas(){
this.height = height;
this.width = width;
x = getWidth()/4;
y = getHeight()/4;
width = getWidth()/2;
height = getHeight()/2;
isFilled = false;
isRound = false;
arcWidth = 10;
arcHeight = 10;
exitCmd = new Command("退出", Command.EXIT, 1);
changeCmd = new Command("改变", Command.SCREEN, 1);
addCommand(exitCmd);
addCommand(changeCmd);
setCommandListener(this);
}
public void paint(Graphics g){
g.setColor(0xFFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0);
if(isFilled){
if(isRound){
g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
}
else{
g.fillRect(x, y, width, height);
}
}
else{
if(isRound){
g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}
else{
g.drawRect(x, y, width, height);
}
}
}
public void commandAction(Command c, Displayable d){
if(c == exitCmd){
destroyApp(true);
notifyDestroyed();
}
else if(c == changeCmd){
display.setCurrent(form);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -