javaMe开发消息对话框

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){
  
 } 
}

你可能感兴趣的:(String,null,Class,byte,JavaME)