java me 开发_javaMe开发按钮

按下效果

/**

* @作者 悠宝移动应用平台

* @按钮实现 http://www.ybool.com.cn/

* @版本 V 1.0

*/

public class MyCustomItem extends CustomItem {

//指定按钮上面的内容

private String str;

//指定按钮的开始位置

private int x=0;

private int y=0;

//指定按钮的高度与宽度

private int btnWidth=50;

private int btnHeight=50;

//表示按键状态,true为按下,false为松开.

private boolean keyState=false;

protected MyCustomItem(String str) {

super(null);

this.str=str;

}

protected int getMinContentHeight() {

return btnHeight;

}

protected int getMinContentWidth() {

return btnWidth;

}

protected int getPrefContentHeight(int arg0) {

return getMinContentHeight();

}

protected int getPrefContentWidth(int arg0) {

return getMinContentWidth();

}

protected void paint(Graphics g, int w, int h) {

drawButton(g, str, x, y, w, h);

}

private void drawButton(Graphics g,String str,int x,int y,int w,int h){

if(keyState){

g.setColor(200,120,20);

g.drawRect(x, y, w-1, h-1);

g.setColor(150,120,20);

g.fillRect(x+2, y+2, w-4, h-4);

}else{

g.setColor(150,120,20);

g.drawRect(x, y, w-1, h-1);

g.setColor(200,120,20);

g.fillRect(x+2, y+2, w-4, h-4);

}

g.setColor(0,0,0);

g.drawString(str, (w-6)/2, (h-8)/2, 0);

}

protected void keyPressed(int keyCode) {

keyState=true;

repaint();

}

protected void keyReleased(int keyCode) {

keyState=false;

repaint();

}

}

-----------------------------------------------------------

/**

* @作者 Jcuckoo

* @创建日期 2009-5-11

* @版本 V 1.0

*/

public class MyCustomItemMIDlet extends MIDlet {

private Display display;

private Form form;

public MyCustomItemMIDlet() {

display=Display.getDisplay(this);

form=new Form("自定义按钮测试");

MyCustomItem btn1=new MyCustomItem("1");

MyCustomItem btn2=new MyCustomItem("2");

MyCustomItem btn3=new MyCustomItem("3");

form.append(btn1);

form.append(btn2);

form.append(btn3);

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {

}

protected void startApp() throws MIDletStateChangeException {

display.setCurrent(form);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值