📄 lotterycastform.java
字号:
/*
* @(#)LotteryCastForm.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 LotteryCastForm extends Form implements CommandListener, ItemStateListener
{
private Display display;
/*表示层类*/
private Displayable dsa;
/*数据输入对象*/
public TextField userID; //输入用户ID;
public TextField time; //由用户输入要买多少注
public StringItem money;
/*错误*/
private Alert errorAlert = null;
/*警告*/
private Alert alarmAlert = null;
/*成功*/
private Alert okAlert = null;
//定义离开软键
public Command backCommand = null;
public Command okCommand = null;
private Command goCommand = null;
private Command noCommand = null;
private String info; //保存投注详细信息
private String ballot; //保存用户投注的结果,用胜,平,负
private String ballotIsOK; //判断投注是否成功
private String point; //得到足球彩票第几期
private double sum; //保存要交多少钱
/*-------------------------------------------------------------------
*初始化
*/
public LotteryCastForm(String title, String point, String info, String ballot, Display display, Displayable dsa)
{
super(title);
this.display = display;
this.dsa = dsa;
this.append(info);
this.info = info;
this.point = point;
this.ballot = ballot;
this.time = new TextField("*请输入注数:", "", 30, TextField.NUMERIC);
this.userID = new TextField("* 输入用户ID:", "", 30, TextField.ANY);
this.money = new StringItem("交钱", "");
this.backCommand = new Command("返回", Command.BACK, 2);
this.okCommand = new Command("确定", Command.BACK, 2);
this.addCommand(backCommand);
this.addCommand(okCommand);
this.append(userID);
this.append(time);
this.setCommandListener(this);
this.setItemStateListener(this);
}
/**
*显示对象
*/
private String callServer()
{
String html = "";
if (userID.getString().trim().compareTo("") != 0 && time.getString().trim().compareTo("") != 0)
{
//参数
String parameter = "userID=" + userID.getString().trim() + "&point=" + point
+ "&info=" + info + "&time=" + time.getString().trim()
+ "&money=" + sum + "&ballot=" + ballot;
try
{
//获得服务器用户保存的内容
html = ConnectHttp.invokeJSP(LotteryServerURL.getURL() + "/lottery_ballot.jsp", parameter);
//处理HTML标记语言
html = DisposeHTML.getBody(html);
//判断是否注册成功
ballotIsOK = html;
System.out.println(ballotIsOK);
okAlert = new Alert("INFO", "恭喜您,你投注成功!请继续关注开奖时间。谢谢! ", null, AlertType.ERROR);
okAlert.setTimeout(3000);
errorAlert = new Alert("ERROR", "投注失败, 用户ID不存在,请注册成为俱乐部成员!", null, AlertType.ERROR);
errorAlert.setTimeout(2000);
return html;
}
catch(IOException e)
{
errorAlert = new Alert("ERROR", "投注失败, 网络错误!", null, AlertType.ERROR);
errorAlert.setTimeout(2000);
System.out.println(e);
}
catch(NullPointerException e)
{
System.out.println(e);
}
}
else
{
errorAlert = new Alert("ERROR", "请填写完整您的信息! ", null, AlertType.ERROR);
errorAlert.setTimeout(2000);
return "false";
}
return html;
}
public void showForm()
{
this.display.setCurrent(this);
}
public void commandAction(Command c,Displayable s)
{
if(c == backCommand)
{
this.display.setCurrent(dsa);
}
if (c == okCommand)
{
alarmAlert = new Alert("WARNING", "先生或女士们!请注意!假如您们不是俱乐部成员请先注册!如果是俱乐部成员!请点击ok!", null, AlertType.WARNING);
this.goCommand = new Command("OK", Command.OK, 2);
this.noCommand = new Command("back", Command.BACK, 2);
alarmAlert.addCommand(goCommand);
alarmAlert.addCommand(noCommand);
alarmAlert.setCommandListener(this);
this.display.setCurrent(alarmAlert);
}
if (c == goCommand)
{
if (this.callServer().trim().compareTo("true") == 0)
{
this.display.setCurrent(okAlert, dsa);
}
else
{
this.display.setCurrent(errorAlert, this);
}
}
if (c == noCommand)
{
this.display.setCurrent(dsa);
}
}
public void itemStateChanged(Item item)
{
if (item == time)
{
try
{
/*手续费用*/
double other = Double.parseDouble(time.getString()) * 0.1;
/*总费用*/
sum = other + Double.parseDouble(time.getString()) * 2;
this.money.setText("\n尊敬的客户你选择投注了" + time.getString() + "注" + "\n你应该付手续费用是:" + other
+ "块人民币" + "\n你应该付的总费用是:" + sum + "块人民币");
}
catch(NumberFormatException n)
{
}
try
{
this.insert(1, money);
}
catch(IllegalStateException e)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -