📄 welcomeview.java
字号:
package com.tianxia.qipai.view.universal;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
import javax.microedition.rms.*;
import java.io.*;
import com.tianxia.qipai.control.universal.*;
import com.tianxia.qipai.event.*;
import com.tianxia.qipai.model.util.CommStructNode;
public class WelcomeView extends Canvas implements Runnable{ //绘制欢迎界面
private BeginControl begincontrol; //游戏开始控制模块
private Image welcomeimage; //要显示的欢迎图片
private int imageheight,imagewidth; //图片的高度和宽度
private boolean exitflag; //欢迎界面是否已经退出
private RecordStore recordstore = null; //记录存储器
private CommStructNode commstructnode = null; //各控制器之间的通信结构
private boolean Ifrepaint; //是否重画(重画只画进度条)
private static int guagemaxlen = 100; //进度条最长取值为100
private int achievelen; //进度分段限制取值
private int guagelen,guagewid; //进度条的长和宽
private int guageinc; //进度条增量
public WelcomeView(BeginControl begincontrol) {
super();
// TODO 自动生成构造函数存根
this.begincontrol = begincontrol;
exitflag = false;
welcomeimage = null;
imageheight = imagewidth = 0;
Ifrepaint = false; //置重画标志
achievelen = 50; //第一个操作完成最大显示的进度
guageinc = 5;
try {
welcomeimage = Image.createImage("/png/title.png"); //读取欢迎图片
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
protected void paint(Graphics g) {
// TODO 自动生成方法存根
if(!Ifrepaint){ //判断是否调用repaint函数进行重画
guagelen = 0;
guagewid = getHeight()/25; //进度条宽度设为屏幕高度的25分之一
g.setColor(0,255,255); //设置画笔颜色
g.fillRect(0,0,getWidth(),getHeight()); //画背景色
imagewidth = welcomeimage.getWidth();
imageheight = welcomeimage.getHeight();
//画欢迎图片
g.drawImage(welcomeimage,(getWidth()-imagewidth)/2,20,Graphics.TOP|Graphics.LEFT);
welcomeimage = null;
g.setColor(255,255,255); //设置进度框的画笔颜色
//画进度框
g.drawRect((getWidth()-imagewidth)/2,imageheight+25,guagemaxlen,guagewid);
Ifrepaint = true; ////置重画标志
Thread t = new Thread(this);
t.start(); //启动进度条进度控制线程
UserDataInit(); //初试化用户数据
}
else
{ //画进度条
g.setColor(255,255,255); //设置进度条的画笔颜色
g.fillRect((getWidth()-imagewidth)/2,imageheight + 25,guagelen,guagewid); //画进度条
}
}
public void UserDataInit(){
commstructnode = new CommStructNode();
achievelen = 80; //第二个操作完成最大显示的进度
try {
recordstore = RecordStore.openRecordStore("userdata",true); //打开用户信息的记录存储器
RecordEnumeration recordenumeration = recordstore.enumerateRecords(null,null,false);
achievelen = 100; //第三个操作完成最大显示的进度
if( recordenumeration.hasNextElement() ){ //判断是否有记录
String temp = "";
byte[] byteinputdata = new byte[100];
ByteArrayInputStream byteinputstream = new ByteArrayInputStream(byteinputdata);
DataInputStream inputdatastream = new DataInputStream(byteinputstream);
recordstore.getRecord(recordenumeration.nextRecordId(),byteinputdata,0);
temp = inputdatastream.readUTF();
commstructnode.setUserId(temp); //设置cookies的用户号码
temp = inputdatastream.readUTF();
commstructnode.setPassWord(temp); //设置cookies的密码
}
recordstore.closeRecordStore();
recordenumeration.destroy();
achievelen = 111; //表示初试化完成
} catch (RecordStoreFullException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void run() {
//1.初始化事件变量值(即类CommStructNode的事例初始化)
//2.从记录存储器中读曲用户的登录号码和密码
while(true){
try {
Thread.sleep(200);
guagelen = guagelen + guageinc;
if( guagelen >= achievelen){
guagelen = guagelen - guageinc;
continue;
}
if ( guagelen >= 100){
guagelen = 100;
repaint();
break;
}
repaint();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
MainGameEvent maingameevent = new MainGameEvent();
maingameevent.setByName("stepflag","welcomeviewexit"); //设置当前游戏的进度
maingameevent.setCommNode(commstructnode); //设置通信结点
if(!exitflag){
welcomeimage = null;
begincontrol.rt.gc();
begincontrol.handleEvent(UniGameEvent.WELCOMEVIEWEXIT,maingameevent);
}
}
public void setNull(){
begincontrol = null; //游戏开始控制模块
welcomeimage = null; //要显示的欢迎图片
recordstore = null; //记录存储器
commstructnode = null; //各控制器之间的通信结构
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -