火车售票系统完整代码_第1页
火车售票系统完整代码_第2页
火车售票系统完整代码_第3页
火车售票系统完整代码_第4页
火车售票系统完整代码_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.Result

2、Set;import java.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextArea;import javax.swing.JTextField;publi

3、c class BuyPanel extends JPanel StringBuffer sb = new StringBuffer();private boolean flag = false;JTextArea jtArea = new JTextArea(10, 78);JLabel buyLabel = new JLabel("订票");JTextField fId = new JTextField(7);JTextField ftid = new JTextField(7);JTextField fche = new JTextField(7);JTextFiel

4、d fzhangshu = new JTextField(7);JTextField fbodyId = new JTextField(7);JPasswordField jpField = new JPasswordField(7);public JPanel getBuypn() JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 10

5、0,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(buyLabel, con);con = getGridBagConstraints(0, 2, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan3(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pa

6、n.add(new pan4(), con);con = getGridBagConstraints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;/* * 定义下面购票操作区面板pan3 * * author Administrator * */class pan3 extends JPanel JLabel lId = new JLabel(&

7、quot; 车票号码 ");JLabel ltid = new JLabel(" 车票号码 ");JLabel che = new JLabel(" 车 次 ");JLabel lbodyId = new JLabel(" 身份证号 ");JLabel password = new JLabel(" 密码 ");JLabel lzhangshu = new JLabel(" 所需张数 ");JLabel la1 = new JLabel(" ");JLabel la

8、2 = new JLabel(" ");JButton sureButton = new JButton("查询确认");JButton buyButton = new JButton("确认购票");public pan3() buyButton.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) UpdateUser();if (flag=true)UpdateTrain();System.out.prin

9、tln("hjkasfhjkaf"););sureButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) select(););GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE,

10、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 = getGridBagConstrai

11、nts(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, GridBagConst

12、raints.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,

13、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.EAS

14、T);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,

15、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.EA

16、ST);this.add(buyButton, con);this.setBorder(BorderFactory.createTitledBorder("订票操作区");/* * 定义下面一个JList用于显示车票的所有信息面板pan4 * * author Administrator * */class pan4 extends JPanel JButton btId = new JButton("车票号码");JButton bt1 = new JButton("起 点 站");JButton bt2 = new JButton

17、("终 点 站");JButton bt3 = new JButton("车 次");JButton bt4 = new JButton("发车时间");JButton bt5 = new JButton("到达时间");JButton bt6 = new JButton("座位类型");JButton bt7 = new JButton("发车日期");JButton bt8 = new JButton("剩余票数");JButton bt9 = new

18、 JButton("车票价格");public pan4() this.setLayout(new GridBagLayout();GridBagConstraints con = 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, GridBagConstrain

19、ts.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,

20、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(bt

21、6, 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,GridBagConstr

22、aints.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 * * author Administrator * */class pan5 extends JPanel JButton bt1 = n

23、ew JButton("退出登录");JLabel lab1 = new JLabel(" ");public pan5() GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBag

24、Constraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lab1, con);bt1.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) System.exit(0););/* * 放回一个网格包约束 * * param x * param y * param width * param heigh * param weighx * param

25、weighy * param fill * param anchor * return */private GridBagConstraints getGridBagConstraints(int x, int y, int width,int heigh, int weighx, int weighy, int fill, int anchor) GridBagConstraints con = new GridBagConstraints();con.gridx = x;con.gridy = y;con.gridwidth = width;con.gridheight = heigh;c

26、on.weightx = weighx;con.weighty = weighy;con.fill = fill;con.anchor = anchor;return con;/* * 按车票号码搜索所有的车票信息 * * throws SQLException */private void select() Connection conn = null;Statement stmt = null;ResultSet ticket = null;try conn = DriverManager.getConnection("jdbc:oracle:thin:127.0.0.1:152

27、1:ORCL", "store", "store"); catch (SQLException e1) e1.printStackTrace();try stmt = conn.createStatement();String text = "select * from train_table " + "where tid=" + "'"+ fId.getText() + "'"ticket = stmt.executeQuery(text);whi

28、le (ticket.next() String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime&

29、quot;);String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + fId.getText() + "t"+ " "

30、; + starter + "t"+ " " + reacher+ "t"+ " " + ticketNumber + "t" + startTime + "t"+ endTime + "t" + seatIdNumber + "t" + busDate + "t"+ ticketNum + "t" + price + " " + "n");jtArea.s

31、etText(sb.toString();if (sb.length() > 0) sb.delete(1, sb.length(); else JOptionPane.showMessageDialog(new TestFrame(), "无此车!"); catch (SQLException e) finally if (ticket != null) try ticket.close(); catch (SQLException e) e.printStackTrace();if (stmt != null) try stmt.close(); catch (S

32、QLException e) e.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e) e.printStackTrace();/* * 订票时更新数据库中的车票表 */private void UpdateTrain() String tId=ftid.getText();int num=0;if (fzhangshu.getText().length()>0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgb

33、c.getconnect();CallableStatement cst = null;try conn.setAutoCommit(false);cst = conn.prepareCall("call train_proc (?,?)");cst.setString(1, tId);cst.setInt(2, num);cst.execute();mit(); catch (SQLException e1) try conn.rollback();JOptionPane.showMessageDialog(new TestFrame(), "客户订票失败!&q

34、uot;); catch (SQLException e2) JOptionPane.showMessageDialog(new TestFrame(), "客户订票失败!"); finally if (cst != null) try cst.close(); catch (SQLException e1) e1.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e1) e1.printStackTrace();/* * 订票时更新数据库中的用户表 */private voi

35、d UpdateUser() String tId=ftid.getText();String bId=fbodyId.getText();String cID=fche.getText();String pwd=String.valueOf(jpField.getPassword();int num=0;if(bId.equals(EnterFrame.ID)&&(pwd.equals(EnterFrame.password)if(fzhangshu.getText().length()>0)num=Integer.parseInt(fzhangshu.getText(

36、);Connection conn = Getgbc.getconnect();Statement cst = null;try cst = conn.createStatement();cst.executeUpdate("insert into order_table(tid,id_number,t_num,trainsum)"+ " values('"+ tId+ "','"+ bId+ "','"+ cID + "','"+num+

37、"')");JOptionPane.showMessageDialog(new TestFrame(), "客户订票成功!");flag=true; catch (SQLException e1) JOptionPane.showMessageDialog(new TestFrame(), "订票失败!");flag=false; finally if (cst != null) try cst.close(); catch (SQLException e1) e1.printStackTrace();if (conn !=

38、null) try conn.close(); catch (SQLException e1) e1.printStackTrace();elseJOptionPane.showMessageDialog(new TestFrame(), "您的身份证或密码有误!请查证后再订票"); package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import jav

39、a.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing

40、.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;public class CheckPanel extends JPanel StringBuffer sb = new StringBuffer();JTextField trainField = new JTextField(9);JTextField dateField = new JTextField(9);JTextField stationField = new JTextField(9);JTextField zhiField = new JTex

41、tField(9);JTextArea jtArea = new JTextArea(10, 80);JLabel checkLabel = new JLabel("查询");public JPanel getCheckpn() JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100,GridBagConstrain

42、ts.NONE, GridBagConstraints.WEST);pan.add(checkLabel, con);con = getGridBagConstraints(0, 1, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan2(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan4()

43、, con);con = getGridBagConstraints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;/* * 定义上部查询区面pan2 * * author Administrator * */class pan2 extends JPanel JLabel trainLabel = new JLabel(" 车 次 &q

44、uot;);JLabel dateLabel = new JLabel(" 日 期 ");JLabel stationLabel = new JLabel(" 起点站 ");JLabel zhiLabel = new JLabel(" 终点站 ");JLabel l1 = new JLabel(" ");JLabel l2 = new JLabel(" ");JButton checkButton = new JButton("查 询");JButton flushButto

45、n = new JButton("清 空");JPanel panel1 = new JPanel();JPanel panel2 = new JPanel();JTextArea area = new JTextArea();public pan2() flushButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) trainField.setText(null);stationField.setText(null);zhiField

46、.setText(null);dateField.setText(null);jtArea.setText(null););checkButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) if (dateField.getText().trim().length() > 0) if (trainField.getText().trim().length() > 0| stationField.getText().trim().length()

47、> 0| zhiField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置"); else try dateSelect(); catch (SQLException e1) e1.printStackTrace(); else if (trainField.getText().trim().length() > 0) if (dateField.getText().trim().l

48、ength() > 0| stationField.getText().trim().length() > 0| zhiField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置"); else try idSelect(); catch (SQLException e1) e1.printStackTrace(); else if (stationField.getText().t

49、rim().length() > 0&& zhiField.getText().trim().length() > 0) if (dateField.getText().trim().length() > 0| trainField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置"); else try stationSelect(); catch (SQLEx

50、ception e1) e1.printStackTrace(); else if (dateField.getText().trim().length() <= 0&& stationField.getText().trim().length() <= 0&& zhiField.getText().trim().length() <= 0) if (dateField.getText().trim().length() > 0| stationField.getText().trim().length() > 0| zhiFiel

51、d.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置"); else try allSelect(); catch (SQLException e1) e1.printStackTrace(););JPanel panel3 = new JPanel(new GridBagLayout();panel1.setBorder(BorderFactory.createTitledBorder(&quo

52、t;查询区");panel2.setBorder(BorderFactory.createTitledBorder("售票注意事项");area.setText( "每人每次最多可够买十张火车票,超过十张火车票数的" + "n"+ "请一定要出示您的相关的证件,一旦经过售票员查" + "n" + "询核实并且同意后方可购买");panel2.add(area);GridBagLayout layout = new GridBagLayout();panel1.setLayout(layout);GridBagConstraints con =

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论