火车售票系统完整代码.docx

上传人:b****8 文档编号:8882420 上传时间:2023-02-02 格式:DOCX 页数:66 大小:30.25KB
下载 相关 举报
火车售票系统完整代码.docx_第1页
第1页 / 共66页
火车售票系统完整代码.docx_第2页
第2页 / 共66页
火车售票系统完整代码.docx_第3页
第3页 / 共66页
火车售票系统完整代码.docx_第4页
第4页 / 共66页
火车售票系统完整代码.docx_第5页
第5页 / 共66页
点击查看更多>>
下载资源
资源描述

火车售票系统完整代码.docx

《火车售票系统完整代码.docx》由会员分享,可在线阅读,更多相关《火车售票系统完整代码.docx(66页珍藏版)》请在冰豆网上搜索。

火车售票系统完整代码.docx

火车售票系统完整代码

packagecom.yue;

importjava.awt.Color;

importjava.awt.GridBagConstraints;

importjava.awt.GridBagLayout;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.sql.CallableStatement;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

importjavax.swing.BorderFactory;

importjavax.swing.JButton;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JPasswordField;

importjavax.swing.JTextArea;

importjavax.swing.JTextField;

publicclassBuyPanelextendsJPanel{

StringBuffersb=newStringBuffer();

privatebooleanflag=false;

JTextAreajtArea=newJTextArea(10,78);

JLabelbuyLabel=newJLabel("订票");

JTextFieldfId=newJTextField(7);

JTextFieldftid=newJTextField(7);

JTextFieldfche=newJTextField(7);

JTextFieldfzhangshu=newJTextField(7);

JTextFieldfbodyId=newJTextField(7);

JPasswordFieldjpField=newJPasswordField(7);

publicJPanelgetBuypn(){

JPanelpan=newJPanel();

GridBagLayoutlayout=newGridBagLayout();

pan.setLayout(layout);

GridBagConstraintscon=getGridBagConstraints(0,0,1,1,100,100,

GridBagConstraints.NONE,GridBagConstraints.WEST);

pan.add(buyLabel,con);

con=getGridBagConstraints(0,2,1,1,100,100,

GridBagConstraints.NONE,GridBagConstraints.WEST);

pan.add(newpan3(),con);

con=getGridBagConstraints(0,3,1,1,100,100,

GridBagConstraints.NONE,GridBagConstraints.WEST);

pan.add(newpan4(),con);

con=getGridBagConstraints(0,4,1,1,100,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

pan.add(newpan5(),con);

this.setLocation(270,150);

this.add(pan);

returnpan;

}

/**

*定义下面购票操作区面板pan3

*

*@authorAdministrator

*

*/

classpan3extendsJPanel{

JLabellId=newJLabel("车票号码");

JLabelltid=newJLabel("车票号码");

JLabelche=newJLabel("车次");

JLabellbodyId=newJLabel("身份证号");

JLabelpassword=newJLabel("密码");

JLabellzhangshu=newJLabel("所需张数");

JLabella1=newJLabel("");

JLabella2=newJLabel("");

JButtonsureButton=newJButton("查询确认");

JButtonbuyButton=newJButton("确认购票");

publicpan3(){

buyButton.addActionListener(newActionListener(){

@Override

publicvoidactionPerformed(ActionEvente){

UpdateUser();

if(flag==true){

UpdateTrain();

System.out.println("hjkasfhjkaf");

}

}

});

sureButton.addActionListener(newActionListener(){

@Override

publicvoidactionPerformed(ActionEvente){

select();

}

});

GridBagLayoutlayout=newGridBagLayout();

this.setLayout(layout);

GridBagConstraintscon=getGridBagConstraints(0,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(lId,con);

con=getGridBagConstraints(1,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(fId,con);

con=getGridBagConstraints(8,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(la2,con);

con=getGridBagConstraints(9,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(sureButton,con);

con=getGridBagConstraints(0,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(ltid,con);

con=getGridBagConstraints(1,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(ftid,con);

con=getGridBagConstraints(2,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(che,con);

con=getGridBagConstraints(3,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(fche,con);

con=getGridBagConstraints(4,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(lbodyId,con);

con=getGridBagConstraints(5,1,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(fbodyId,con);

con=getGridBagConstraints(0,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(password,con);

con=getGridBagConstraints(1,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(jpField,con);

con=getGridBagConstraints(2,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(lzhangshu,con);

con=getGridBagConstraints(3,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(fzhangshu,con);

con=getGridBagConstraints(8,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(la1,con);

con=getGridBagConstraints(9,2,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(buyButton,con);

this.setBorder(BorderFactory.createTitledBorder("订票操作区"));

}

}

/**

*定义下面一个JList用于显示车票的所有信息面板pan4

*

*@authorAdministrator

*

*/

classpan4extendsJPanel{

JButtonbtId=newJButton("车票号码");

JButtonbt1=newJButton("起点站");

JButtonbt2=newJButton("终点站");

JButtonbt3=newJButton("车次");

JButtonbt4=newJButton("发车时间");

JButtonbt5=newJButton("到达时间");

JButtonbt6=newJButton("座位类型");

JButtonbt7=newJButton("发车日期");

JButtonbt8=newJButton("剩余票数");

JButtonbt9=newJButton("车票价格");

publicpan4(){

this.setLayout(newGridBagLayout());

GridBagConstraintscon=getGridBagConstraints(0,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(btId,con);

con=getGridBagConstraints(1,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt1,con);

con=getGridBagConstraints(2,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt2,con);

con=getGridBagConstraints(3,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt3,con);

con=getGridBagConstraints(4,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt4,con);

con=getGridBagConstraints(5,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt5,con);

con=getGridBagConstraints(6,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt6,con);

con=getGridBagConstraints(7,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt7,con);

con=getGridBagConstraints(8,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt8,con);

con=getGridBagConstraints(9,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt9,con);

con=getGridBagConstraints(0,1,11,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(jtArea,con);

jtArea.setBackground(Color.GREEN);

}

}

/**

*定义最下面的按钮面板pan5

*

*@authorAdministrator

*

*/

classpan5extendsJPanel{

JButtonbt1=newJButton("退出登录");

JLabellab1=newJLabel("");

publicpan5(){

GridBagLayoutlayout=newGridBagLayout();

this.setLayout(layout);

GridBagConstraintscon=getGridBagConstraints(0,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(bt1,con);

con=getGridBagConstraints(1,0,1,1,0,100,

GridBagConstraints.NONE,GridBagConstraints.EAST);

this.add(lab1,con);

bt1.addActionListener(newActionListener(){

@Override

publicvoidactionPerformed(ActionEvente){

System.exit(0);

}

});

}

}

/**

*放回一个网格包约束

*

*@paramx

*@paramy

*@paramwidth

*@paramheigh

*@paramweighx

*@paramweighy

*@paramfill

*@paramanchor

*@return

*/

privateGridBagConstraintsgetGridBagConstraints(intx,inty,intwidth,

intheigh,intweighx,intweighy,intfill,intanchor){

GridBagConstraintscon=newGridBagConstraints();

con.gridx=x;

con.gridy=y;

con.gridwidth=width;

con.gridheight=heigh;

con.weightx=weighx;

con.weighty=weighy;

con.fill=fill;

con.anchor=anchor;

returncon;

}

/**

*按车票号码搜索所有的车票信息

*

*@throwsSQLException

*/

privatevoidselect(){

Connectionconn=null;

Statementstmt=null;

ResultSetticket=null;

try{

conn=DriverManager.getConnection(

"jdbc:

oracle:

thin:

@127.0.0.1:

1521:

ORCL","store","store");

}catch(SQLExceptione1){

e1.printStackTrace();

}

try{

stmt=conn.createStatement();

Stringtext="select*fromtrain_table"+"wheretid="+"'"

+fId.getText()+"'";

ticket=stmt.executeQuery(text);

while(ticket.next()){

Stringstarter=ticket.getString("starter");

Stringreacher=ticket.getString("reacher");

StringticketNumber=ticket.getString("ticketNumber");

StringstartTime=ticket.getString("startTime");

StringendTime=ticket.getString("endTime");

StringseatIdNumber=ticket.getString("seatIdNumber");

StringbusDate=ticket.getString("busDate");

intticketNum=ticket.getInt("ticketNum");

doubleprice=ticket.getDouble("price");

sb.append(""+fId.getText()+"\t"+""+starter+"\t"+""+reacher

+"\t"+""+ticketNumber+"\t"+startTime+"\t"

+endTime+"\t"+seatIdNumber+"\t"+busDate+"\t"

+ticketNum+"\t"+price+""+"\n");

}

jtArea.setText(sb.toString());

if(sb.length()>0){

sb.delete(1,sb.length());

}else{

JOptionPane.showMessageDialog(newTestFrame(),"无此车!

");

}

}catch(SQLExceptione){

}finally{

if(ticket!

=null){

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1