关闭

javaMe开发消息对话框

330人阅读 评论(0) 收藏 举报

package test;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

public class MessageDialog extends BaseDialog {
 
 private String Mesasge="";
 private boolean buttonSelected=false;
 private String buttonTitle="确定";
 private Font buttonFont=null;
 
 public void paintContainer(Graphics graphics) { 
  paintButton(graphics);
 }
 public void setButtonTitle(String buttonName){//按钮的名字
  buttonTitle=buttonName;
  repaint();
 }
 
 private void paintButton(Graphics graphics){
  if(buttonFont==null){
   buttonFont=Font.getDefaultFont();   
  }
  
  graphics.setColor(0);
  graphics.drawRect(this.getX()+15, this.getY()+this.getHight()-40,this.getWidth()-30,30);
    if(!buttonSelected){
      graphics.setColor(0XBCBCBC);
    graphics.fillRect(this.getX()+16, this.getY()+this.getHight()-38,this.getWidth()-31,28);
    }
    else if(buttonState==-5&&buttonSelected){
     graphics.setColor(198);
     graphics.fillRect(this.getX()+16, this.getY()+this.getHight()-38,this.getWidth()-31,28);
    }
    else{
     graphics.setColor(0X54678);
     graphics.fillRect(this.getX()+16, this.getY()+this.getHight()-38,this.getWidth()-31,28);
    }
    if(buttonSelected)
     graphics.setColor(0XFFFFFF);
    else
     graphics.setColor(0);
    graphics.drawString(buttonTitle,this.getX()+1+(this.getWidth()-buttonFont.getHeight())/2,this.getY()+this.getHight()-23-buttonFont.getHeight()/2, 0);
 } 
 private byte buttonState=0;
 protected void keyPressed(int keyCode) { 
  
  if(keyCode==-5&&buttonSelected){   
   buttonState=(byte)-5;
    repaint();   
    return;
  }
  if(keyCode==-4||keyCode==-3||keyCode==-1||keyCode==-2||keyCode==-5)
   buttonSelected=true;   
      repaint();
 }
 protected void keyReleased(int keyCode){
   buttonState=0;
   buttonSelected=false;
   repaint();
 }
 protected void keyRepeated(int keyCode){
  
 } 
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:219743次
    • 积分:4163
    • 等级:
    • 排名:第8171名
    • 原创:96篇
    • 转载:325篇
    • 译文:6篇
    • 评论:76条
    博客专栏
    文章分类