要求写出所有实现代码
1, 编写一个简单的MIDlet应用,实现提醒功能。
创建5个Command按钮,包括警报,确认,错误,警告及退出按钮。
2, 编写一个事件处理程序,当按下不同按键时显示不同背景颜色。(至少三种背景色)
3, 编写MIDLet实现Graphics类的填充弧形功能。
要求写出所有实现代码
1, 编写一个简单的MIDlet应用,实现提醒功能。
创建5个Command按钮,包括警报,确认,错误,警告及退出按钮。
2, 编写一个事件处理程序,当按下不同按键时显示不同背景颜色。(至少三种背景色)
3, 编写MIDLet实现Graphics类的填充弧形功能。
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public class MIDlet1 extends MIDlet {
public MIDlet1() {}
protected void startApp() {
Display.getDisplay(this).setCurrent(new lCanvas(this));
}
protected void pauseApp() {}
protected void destroyApp(boolean arg0) {
notifyDestroyed();
}
public void exitApp(){
destroyApp(true);
}
public class lCanvas extends Canvas{
public int SW,SH;
public int bgColor=0x000000;
MIDlet1 midlet;
int huDu=90;
Font fontSmall = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN, Font.SIZE_SMALL);
public lCanvas(MIDlet1 midlet){
this.midlet=midlet;
setFullScreenMode(true);
SW=this.getWidth();
SH=this.getHeight();
}
protected void paint(Graphics g) {
g.setFont(fontSmall);
g.setClip(0, 0, SW, SH);
g.setColor(bgColor);
g.fillRect(0, 0, SW, SH);
//===================
g.setColor(0xFFFFFF);
g.drawString("按123键分别显示不同的背景颜色", 2, 2, 0);
g.drawString("按4键减小弧度按6键加大弧度", 2, 17, 0);
g.drawString("按0键分退出", 2, 32, 0);
//====绘制弧形
drawHuxing(g);
}
public void keyPressed(int keycode){
switch(keycode){
case Canvas.KEY_NUM1:
bgColor=0xff0000;
break;
case Canvas.KEY_NUM2:
bgColor=0x00ff00;
break;
case Canvas.KEY_NUM3:
bgColor=0x0000ff;
break;
case Canvas.KEY_NUM4:
if(huDu>0){
huDu-=10;
}
break;
case Canvas.KEY_NUM6:
if(huDu<360){
huDu+=10;
}
break;
case Canvas.KEY_NUM0:
midlet.exitApp();
break;
}
repaint();
}
//绘制弧形
public void drawHuxing(Graphics g){
g.setColor(0xffffff);
g.fillArc(40, 50, 100, 100, 0, huDu);
}
}
}
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public class MIDlet1 extends MIDlet {
public MIDlet1() {}
protected void startApp() {
Display.getDisplay(this).setCurrent(new lCanvas(this));
}
protected void pauseApp() {}
protected void destroyApp(boolean arg0) {
notifyDestroyed();
}
public void exitApp(){
destroyApp(true);
}
public class lCanvas extends Canvas{
public int SW,SH;
public int bgColor=0x000000;
MIDlet1 midlet;
int huDu=90;
Font fontSmall = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN, Font.SIZE_SMALL);
public lCanvas(MIDlet1 midlet){
this.midlet=midlet;
setFullScreenMode(true);
SW=this.getWidth();
SH=this.getHeight();
}
protected void paint(Graphics g) {
g.setFont(fontSmall);
g.setClip(0, 0, SW, SH);
g.setColor(bgColor);
g.fillRect(0, 0, SW, SH);
//===================
g.setColor(0xFFFFFF);
g.drawString("按123键分别显示不同的背景颜色", 2, 2, 0);
g.drawString("按4键减小弧度按6键加大弧度", 2, 17, 0);
g.drawString("按0键分退出", 2, 32, 0);
//====绘制弧形
drawHuxing(g);
}
public void keyPressed(int keycode){
switch(keycode){
case Canvas.KEY_NUM1:
bgColor=0xff0000;
break;
case Canvas.KEY_NUM2:
bgColor=0x00ff00;
break;
case Canvas.KEY_NUM3:
bgColor=0x0000ff;
break;
case Canvas.KEY_NUM4:
if(huDu>0){
huDu-=10;
}
break;
case Canvas.KEY_NUM6:
if(huDu<360){
huDu+=10;
}
break;
case Canvas.KEY_NUM0:
midlet.exitApp();
break;
}
repaint();
}
//绘制弧形
public void drawHuxing(Graphics g){
g.setColor(0xffffff);
g.fillArc(40, 50, 100, 100, 0, huDu);
}
}
}
以上代码实现你了你后面2题
效果图如上,如有不明白的地方你可M我!