⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lotterychoice.java

📁 手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环境是:jsdk1.4以上
💻 JAVA
字号:
/**
 * @(#)LotteryChoice.java	1.11 01/08/23
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	余煜辉
 */

package com.j2me.football.football_lottery;

import com.j2me.football.*;
import com.j2me.language.*;
import com.j2me.common.*;
import java.io.*;
import javax.microedition.lcdui.*;


/**
 *此类是用来下载竟猜的比赛项目,并被用户作出选择
 */
public class LotteryChoice extends Form implements CommandListener, ItemStateListener
{
	/*显示类*/
	private Display display = null;

	/*动感足球主菜单*/
	private LotteryList lotteryList = null;

	/*足采俱乐部注册类*/
	public RegisterFotteryForm register = null;

	/*投注显示层类*/
	private LotteryCastForm L_C_F = null;
												
	/*错误*/
	private Alert errorAlert = null;

	/*软件类*/
	private Command backCommand = null;
	private Command okCommand = null;
	private Command registerCommand = null;
	private Command helpCommand = null;

	/*得到用户选择足彩的代码*/
	private int[] footCode = new int[13];
	
	/*获得用户选择足球彩票的字符代码*/
	private String[] stringCode = new String[13];

	/*此变量用于把数组转换为字符串保存的变量, 这样有利于参数传递*/
	private String footCodeString = null;

	/*保存从网络下载下来的数据*/
	public String[] item = new String[14];

	/*定义ChoiceGroup对象数组用来用户选择足球投注*/
	private ChoiceGroup[] choice = null;

	/*-----------------------------------------------------------------------
	 *构造方法
	 */
	public LotteryChoice(String title, Display display, LotteryList lotteryList)
	{
		super("");
		this.display = display;
	   	this.lotteryList = lotteryList;
		this.backCommand = new Command("返回", Command.BACK, 2);
		this.okCommand = new Command("投注", Command.OK, 2);
		this.registerCommand = new Command("注册", Command.OK, 2);
		this.helpCommand = new Command("帮助", Command.OK, 2);

		this.addCommand(backCommand);
		this.addCommand(okCommand);
		this.addCommand(registerCommand);
		this.addCommand(helpCommand);
		this.setCommandListener(this);
		this.setItemStateListener(this);
		this.init(title);
	}

    /**
	 *初始化
	 */
	public void init(String title)
	{
		//new13个ChoiceGroup对象是因为意大利甲级联赛没一轮有13场比赛*/
		this.choice = new ChoiceGroup[13];
		String html = "";
		String[] result = {"胜", "平", "负"};  //用于给用户判断胜负
		this.choice = new ChoiceGroup[13];

		/*初始化用户全部买赢*/
		for (int n = 0; n < 13; n++)
		{
			this.footCode[n] = 3;
		}
        
		/*初始化用户全部买赢*/
		for (int n = 0; n < 13; n++)
		{
			this.stringCode[n] = "胜";
		}


		/* Thread t = new Thread() 
		{   				 				 
			public void run() 
			{ */
			try
			{	
				//获得服务器用户保存的内容
			    html = ConnectHttp.invokeJSP(LotteryServerURL.getURL() + "/football_lottery.jsp");
				
				//处理HTML标记语言
				html = DisposeHTML.getBody(html);	

				//把Unicode字符转换为中文
				//html = Unicode.unicodeToString(html);
				System.out.println(html);
			}
			catch(IOException e)
			{
				this.display.setCurrent(errorAlert);
				System.out.println(e);
			}
		/* }						
		};
	   t.start();*/	  //启动线程让它进行连网	

	   /*通过类DisposeData把html转换为我想要的字符串数组*/
	   item = DisposeData.getStringGroup(html, "~", 14);
	   this.setTitle(title + item[0]);
	   for (int i = 0; i < this.choice.length; i++ )
	   {
		   int h = i + 1;
		   //创建足球选择对象
		   this.choice[i] = new ChoiceGroup("第 " + h + " 场: " + item[i+1].trim(), Choice.EXCLUSIVE);
		   //设置布局
		   this.choice[i].setLayout(Item.LAYOUT_RIGHT);
		   for (int j = 0; j < 3; j++ )
		   {	
			   //增加子项
			   this.choice[i].append(result[j], null);
		   }
		   this.append(choice[i]);
	   }

	}

	/*显示菜单界面方法
	public void showForm(Display display, LotteryList lotteryList)	//用来显示界面
	{		
		this.display = display;
	   	this.lotteryList = lotteryList;
		this.display.setCurrent(this);
	}  */

    /*
	 *实现监听方法
	 */
	public void commandAction(Command c, Displayable s)
	{
		if(c == backCommand)
		{
			this.display.setCurrent(lotteryList);
		}

		if (c == okCommand)
		{
			String info = "你投注的详细信息如下:\n";
			String ballot = "";
			for (int i = 0; i < 13; i++ )
			{
				info += item[i+1] + "  " + stringCode[i] + "\n"; 
				ballot += stringCode[i];
			}


			/*判断用户选择的语言*/
			if (Language.isEnglish)
			{
				L_C_F = new LotteryCastForm("Balloc Info" + item[0], item[0], info, ballot, display, this);
				L_C_F.userID.setLabel("*Enter userID:");
				L_C_F.time.setLabel("*Enter time:");
				L_C_F.showForm();
			}
			else
			{
				L_C_F = new LotteryCastForm("投注信息" + item[0], item[0], info, ballot, display, this);
				L_C_F.userID.setLabel("*输入ID:");
				L_C_F.time.setLabel("*输入注数:");
				L_C_F.showForm();
			}		
		}

		if (c == registerCommand)
		{
			register = new RegisterFotteryForm();
			register.showForm(display, this);

		}

		if (c == helpCommand)
		{
			HelpAlert h = new HelpAlert("Help");
			this.display.setCurrent(h);
		}
	}

	
	/**
	 *实现Item改变的监视器
	 */
	public void itemStateChanged(Item item)	   
    {
		/*判断用户的选择,并保存到数组里,以便发送到服务器上*/
		for (int i = 0; i < 13; i++  )
		{	 
			if (item == choice[i])
			{
				/*用循环来判断用户的选择*/
				for (int j = 0; j < 3; j++)
				{
					if (choice[i].isSelected(j) == true)
					{		
						footCode[i] = DisposeData.getIntGroup(choice[i].getString(choice[i].getSelectedIndex()));
						stringCode[i] = choice[i].getString(choice[i].getSelectedIndex());
						System.out.println("B: " + footCode[i]);
						System.out.println(stringCode[i]);
					}
				}
												
			}
		}

	}
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -