文件名称:火车售票系统
文件大小:5KB
文件格式:JAVA
更新时间:2015-07-15 10:55:27
java 火车
import java.util.*;
import java.sql.*;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
public class BookTheTicket implements Runnable{
private Thread clocker,time;
String s1,s2,s3,s4;
long startTime,endTime;
long nowTime, leftTime, leftSec, leftMin;
boolean flag=false;
private char chs[]=new char[8];
private Connection con = null;
private Statement stmt = null;
ResultSet rs=null,rs2=null;
String str;
public BookTheTicket(String s1,String s2,String s3,String s4)
{
this.s1=s1;//用户名
this.s2=s2;//订票数量
this.s3=s3;//车次
this.s4=s4;//定第n天的票
clocker = new Thread(this,"clock");
clocker.start();
time=new Thread(this,"ti");
time.start();
}
//生成随机码
//*******************************************************************************************************************************************//
public void play()
{
SimpleDateFormat dateFormat = new SimpleDateFormat();
long endtime;
Calendar startCalendar = Calendar.getInstance();
endtime=startCalendar.getTime().getTime()+48*60*60*1000;
//获取系统当天时间并加两天
for(int i=0;i<8;i++)
{ Random r2=new Random();
int m=0;
do
{
m=r2.nextInt(124);
}while(m<48||m>122||(m>90&&m<97)||(m>57&&m<65));
chs[i]=(char)m; //将筛选合格的字符存储在chs数组中
}
str=String .valueOf(chs[0]); //获取chs[i]给str 如果不进行此步,str默认是null,合并后的字符串总以null开头
for(int j=1;j