购票系统
购票系统
此购票系统是一个单机系统,我在数据库读取过程中遇到了困难,暂时没有办法解决
思路
使用三层架构的方法,把实现方法,实现接口和实体对象分离,再在测试类中运行
界面Gui构建
//定义路线的组件
JLabel jl1,jl2;
JComboBox comBox1;
JButton jb1;
JPanel jp4,jp_top;
//定义显示车票数据的组件
JTextArea jta;
JScrollPane jsp;
//定义显示购买的组件
JPanel jp2,jp3,jp_bottom;
JLabel jl3,jl4,jl5,jl6;
JComboBox comBox2,comBox3;
JTextField jtf1,jtf2;
JButton jb2,jb3,jb_exit;
控件判断方法
synchronized (this) {
if (Thread.currentThread().getName().equals("1号窗")) {
int ticketCount = Integer.parseInt(jtfOne.getText());
for (int i = 0; i < 4; i++) {
Route routeTemp = list.get(i);
if (comOne.getSelectedItem().toString() == "2001"
&& routeTemp.getRouteId() == "2001") {
int ticket = routeTemp.getRouteTicket();
if (ticket - ticketCount >= 0) {
ticket = ticket - ticketCount;
routeTemp.setRouteTicket(ticket);
showMeaage.append(Thread.currentThread().getName()
+ "售票,2001班列车,车票剩下: " + ticket);
showMeaage.append("\n");
} else {
showMeaage.append("车票不够,请查询具体班次列车的剩余票数。");
showMeaage.append("\n");
}
}
if (comOne.getSelectedItem().toString() == "2002"
&& routeTemp.getRouteId() == "2002") {
int ticket = routeTemp.getRouteTicket();
if (ticket - ticketCount >= 0) {
ticket = ticket - ticketCount;
routeTemp.setRouteTicket(ticket);
showMeaage.append(Thread.currentThread().getName()
+ "售票,2002班列车,车票剩下: " + ticket);
showMeaage.append("\n");
} else {
showMeaage.append("车票不够,请查询具体班次列车的剩余票数。");
showMeaage.append("\n");
}
}
之后为完成分割字符串的功能,我找了很久,找不到完美的方法,最后无可奈何只能把范围限定在英文内,并且必须是以逗号为分割,通过split方法将字符串分开并储存在数组中。
//通过readline方法读取方便又快捷,把读取到的东西赋值给a,创建g字符串将编码改为gbk编码
while((a=fis.readLine())!=null) {
getline++;
g=new String(a.getBytes("ISO-8859-1"), "gbk");
String[] idArr = g.split(",");
String mid = null;
for(int i =0;i < idArr.length;i++) {
mid = idArr[i];
//if的判断来判断键值的累积
if(!tm.containsKey(mid)) {
tm.put(mid, 1);
}
else {
tm.put(mid, tm.get(mid)+1);
}
}
}
实体类属性
private String routeId ;
private String routeTime;
private int routeTicket;
private float routeMoney;
public float getRouteMoney() {
return routeMoney;
}
public void setRouteMoney(float routeMoney) {
this.routeMoney = routeMoney;
}
public int getRouteTicket() {
return routeTicket;
}
public void setRouteTicket(int routeTicket) {
this.routeTicket = routeTicket;
}
public String getRouteId() {
return routeId;
}
public String getRouteTime() {
return routeTime;
}
public void setRouteId(String routeId) {
this.routeId = routeId;
}
public void setRouteTime(String routeTime) {
this.routeTime = routeTime;
}