📄 gameshowdialog.java
字号:
package cn.org.matrix.gmatrix.practice.demo01;
import javax.microedition.lcdui.Font;
import cn.org.matrix.gmatrix.gameLab.control.KeyManager;
import cn.org.matrix.gmatrix.gameLab.util.ui.*;
/**
* 显示消息的对话框
* @author cleverpig
*
*/
public class GameShowDialog extends GameDialogBox{
/**
* 构造方法
* @param showContent 对话框中显示的文字
* @param bgColor 背景颜色
* @param uiBgColor UI背景颜色
* @param borderColor UI边界颜色
* @param contentColor 文字颜色
*/
public GameShowDialog(String showContent,
int bgColor,int uiBgColor,int borderColor,int contentColor){
super();
//初始化描述性文字对象
Description des=new Description();
des.setContent(showContent);
des.setContentColor(contentColor);
des.setFont(Font.getDefaultFont());
//初始化色彩方案
this.getColorScheme().setBgColor(bgColor);
this.getColorScheme().setUIBgColor(uiBgColor);
this.getColorScheme().setUIBorderColor(borderColor);
this.setDescription(des);
//设置确认键和取消键
this.setAffirmKey(KeyManager.OK_KEYPRESS);
this.setCancelKey(KeyManager.CANCEL_KEYPRESS);
//设置UI范围
this.getScope().setUIHeight(this.getHeight()/3);
this.getScope().setUIWidth(this.getWidth()/2);
this.getScope().setLeftTopCoordinates(this.getWidth()/4,this.getHeight()/4);
//设置填充的高度、宽度
this.setStuffingHeight(10);
this.setStuffingWidth(10);
//设置对话框类型
this.setType(GameDialogBox.CLOSE_UNTILTIMEOUT);
//设置对话框等待时间
this.setWaitTime(2000);
}
/**
* 初始化
*/
public void init(){
this.setTimer(0);
this.setRunning(true);
}
/**
* 线程的run方法
*/
public void run(){
System.out.println("对话框启动");
while(this.isRunning()){
try{
Thread.sleep(500);
}
catch(Exception ex){
}
//根据对话框类型判断是否选择完毕退出线程
switch(this.getType()){
case GameUI.NEVERCLOSE_UNTILKEYPRESS:
if (this.getSelectedValue()>0){
this.setRunning(false);
}
break;
case GameUI.CLOSE_UNTILTIMEOUT:
if (this.getTimer()>=this.getWaitTime()){
this.setSelectedValue(TIMEOUT);
this.setRunning(false);
}
System.out.println("计时器:"+this.getTimer());
this.setTimer(this.getTimer()+500);
break;
}
}
System.out.println("对话框退出");
MainMIDlet.gameNavigator.switchSomething(GameNavigator.MENU_CANVAS);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -