public void paint(Graphics g){
//清除屏幕
int color = g.getColor();
g.setColor(0xFFFFFF);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(color);
//计算整个菜单的高度,宽度和(x,y)
int rectWidth = preferWidth;
int rectHeight = preferHeight * LABELS.length;
int x = (getWidth()-rectWidth)/2;
int y = (getHeight()-rectHeight)/2;
//画矩形
g.drawRect(x,y,rectWidth,rectHeight);
for(int i = 1;i
g.drawLine(x,y+preferHeight*i,x+rectWidth,y+preferHeight*i);
}
//画菜单选项,并根据selected的值判断焦点
for(int j = 0;j if(selected == j){
g.setColor(0x6699cc);
g.fillRect(x+1,y+j*preferHeight+1,rectWidth-1,preferHeight-1);
g.setColor(color);
}
g.drawString(LABELS[j],x+8,y+j*preferHeight+4,Graphics.LEFT|Graphics.TOP);
}
}