?? hall.java
字號:
package com.dfun.blackjack;
import javax.microedition.lcdui.*;
/**************************************************
* @author Beetle
* 類功能介紹:房屋管理
**************************************************/
public class Hall
implements CommandListener {
/**************************************************
*定義公用變量
**************************************************/
private Main main; //主控程序
private String phoneNumber; //電話號碼
private Connection conn; //連接對象
private Display display; //顯示管理
public String[][] houseList; //房間列表,值依次為:房間id,房間名稱,莊家id,莊家名稱,人數上限,現有人數
private Image img[]; //圖片數組
/**************************************************
*定義主窗體變量
**************************************************/
private Form mainForm; //大廳窗體
public ChoiceGroup choHouseList; //房間列表
private Command cmdNewHouse; //新建房間
private Command cmdInto; //進入房間
private Command cmdRefresh; //刷新按扭
/**************************************************
*定義新建窗體變量
**************************************************/
private Form newHouse; //新建房間
private TextField maxClient; //人數上限
private TextField houseName; //房間名稱
private Command cmdRequest; //提交
private Command cmdCancel; //取消
/*******************************************************
* 功能介紹:構造函數
* 輸入參數:顯示管理,連接對象,手機號碼,主程序
*******************************************************/
public Hall(Display display, Connection conn, String phoneNumber, Main main) {
/**************************************************
*初始化公用變量
**************************************************/
this.main = main;
this.phoneNumber = phoneNumber;
this.conn = conn;
this.display = display;
img = main.loadImg(3);
/**************************************************
*初始化主窗體變量
**************************************************/
choHouseList = new ChoiceGroup(null, List.EXCLUSIVE); //房間列表
mainForm = new Form("游戲大廳");
mainForm.append("請選擇房間,如果人數上限或游戲已開始則不能進入!");
mainForm.append(choHouseList);
cmdRefresh = new Command("刷新", Command.OK, 1);
cmdNewHouse = new Command("新建", Command.OK, 1);
mainForm.addCommand(cmdRefresh);
cmdInto = new Command("進入", Command.OK, 1);
mainForm.addCommand(cmdNewHouse);
mainForm.addCommand(cmdInto);
mainForm.setCommandListener(this);
/**************************************************
*初始化新建窗體變量
**************************************************/
newHouse = new Form("新建房間");
houseName = new TextField("房間名稱", main.strUserName + "所建房間", 15, TextField.ANY);
maxClient = new TextField("游戲人數,人數到達后游戲自動開始", "", 2, TextField.NUMERIC);
cmdRequest = new Command("提交", Command.OK, 1);
cmdCancel = new Command("取消", Command.BACK, 1);
newHouse.append(houseName);
newHouse.append(maxClient);
newHouse.addCommand(cmdRequest);
newHouse.addCommand(cmdCancel);
newHouse.setCommandListener(this);
}
/*****************************************************
* 功能介紹:顯示游戲大廳
* 輸入參數:無
* 輸出參數:無
*****************************************************/
public void showHall() {
houseName.setString(main.strUserName + "所建房間");
while (choHouseList.size() != 0) {
choHouseList.delete(0);
}
for (int j = 0; j < houseList.length; j++) {
choHouseList.append(houseList[j][1], img[0]);
}
display.setCurrent(mainForm);
main.refreshState = 0;
}
/*****************************************************
* 功能介紹:刷新游戲大廳
* 輸入參數:無
* 輸出參數:無
*****************************************************/
public void refreshHall(String inputStr) {
houseList=main.split(inputStr,",",6);
ChoiceGroup choiceTmp = new ChoiceGroup(null, List.EXCLUSIVE); ;
for (int j = 0; j < houseList.length; j++) {
choiceTmp.append(houseList[j][1], null);
}
choHouseList = choiceTmp;
mainForm.delete(1);
mainForm.append(choHouseList);
if(mainForm==display.getCurrent()){
display.setCurrent(mainForm);
}
}
public void commandAction(Command c, Displayable d) {
if (c == cmdRefresh && d == mainForm) { //刷新游戲大廳
if (!conn.getHouseList()) {
display.setCurrent(new Alert("系統提示", "對不起網絡信號不好取數據失敗請稍候重試!", null, AlertType.ERROR));
}
}
if (c == cmdInto && d == mainForm) { //進入房間
if (choHouseList.getSelectedIndex() < 0) {
display.setCurrent(new Alert("系統提示", "對不起您沒有選定房間!", null, AlertType.ERROR));
return;
}
int index = choHouseList.getSelectedIndex();
main.house.intoHouse(index);
}
if (c == cmdNewHouse && d == mainForm) { //新建房間
display.setCurrent(newHouse);
}
if (c == cmdCancel && d == newHouse) { //取消
display.setCurrent(mainForm);
}
if (c == cmdRequest && d == newHouse) { //提交
if (houseName.size() <= 0) {
display.setCurrent(new Alert("系統提示", "您還未填寫房間名稱!", null, AlertType.ERROR));
return;
}
if (maxClient.size() <= 0) {
display.setCurrent(new Alert("系統提示", "您還未填寫游戲人數!", null, AlertType.ERROR));
return;
}
if (Integer.parseInt(maxClient.getString()) < 1 || Integer.parseInt(maxClient.getString()) > 4) {
display.setCurrent(new Alert("系統提示", "您填寫的人數必須是1至4!", null, AlertType.ERROR));
return;
}
long houseId = conn.addHouse(houseName.getString(), main.userId, main.strUserName, Integer.parseInt(maxClient.getString()));
main.house.intoHouse(houseId, houseName.getString(), main.userId, main.strUserName, Integer.parseInt(maxClient.getString()));
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -