收藏 分销(赏)

火车售票系统完整代码教学内容.doc

上传人:天**** 文档编号:3869671 上传时间:2024-07-22 格式:DOC 页数:44 大小:159.50KB
下载 相关 举报
火车售票系统完整代码教学内容.doc_第1页
第1页 / 共44页
火车售票系统完整代码教学内容.doc_第2页
第2页 / 共44页
火车售票系统完整代码教学内容.doc_第3页
第3页 / 共44页
火车售票系统完整代码教学内容.doc_第4页
第4页 / 共44页
火车售票系统完整代码教学内容.doc_第5页
第5页 / 共44页
点击查看更多>>
资源描述

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.Resul

2、tSet;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;publ

3、ic 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);JTextField fzhangshu

4、 = 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, 100,GridBagCo

5、nstraints.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);pan.add(new p

6、an4(), 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( 车票号码 );JLab

7、el ltid = new JLabel( 车票号码 );JLabel che = new JLabel( 车 次 );JLabel lbodyId = new JLabel( 身份证号 );JLabel password = new JLabel( 密码 );JLabel lzhangshu = new JLabel( 所需张数 );JLabel la1 = new JLabel( );JLabel la2 = new JLabel( );JButton sureButton = new JButton(查询确认);JButton buyButton = new JButton(确认购票);

8、public pan3() buyButton.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) UpdateUser();if (flag=true)UpdateTrain();System.out.println(hjkasfhjkaf););sureButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) select(););

9、GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = 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);th

10、is.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, 1

11、00,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,

12、 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,GridBagCon

13、straints.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, c

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

15、agConstraints.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 * * author Administrator

16、* */class pan4 extends JPanel JButton btId = new JButton(车票号码);JButton bt1 = new JButton(起 点 站);JButton bt2 = new JButton(终 点 站);JButton bt3 = new JButton(车 次);JButton bt4 = new JButton(发车时间);JButton bt5 = new JButton(到达时间);JButton bt6 = new JButton(座位类型);JButton bt7 = new JButton(发车日期);JButton bt8

17、= new JButton(剩余票数);JButton bt9 = new 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,GridBagConstrain

18、ts.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 = getGridBa

19、gConstraints(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, GridBagCons

20、traints.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

21、, 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 * * author Administrator * */class pan5 exten

22、ds JPanel JButton bt1 = new 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 = getGridBa

23、gConstraints(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

24、 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;

25、con.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:1521:ORC

26、L, 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);while (ticket.next() String starter = ticket.getString(starter);String reacher = ticket.getStrin

27、g(reacher);String ticketNumber = ticket.getString(ticketNumber);String startTime = ticket.getString(startTime);String endTime = ticket.getString(endTime);String seatIdNumber = ticket.getString(seatIdNumber);String busDate = ticket.getString(busDate);int ticketNum = ticket.getInt(ticketNum);double pr

28、ice = 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.showMes

29、sageDialog(new TestFrame(), 无此车!); catch (SQLException e) finally if (ticket != null) try ticket.close(); catch (SQLException e) e.printStackTrace();if (stmt != null) try stmt.close(); catch (SQLException e) e.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e) e.printStackT

30、race();/* * 订票时更新数据库中的车票表 */private void UpdateTrain() String tId=ftid.getText();int num=0;if (fzhangshu.getText().length()0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgbc.getconnect();CallableStatement cst = null;try conn.setAutoCommit(false);cst = conn.prepareCall(call train_pro

31、c (?,?);cst.setString(1, tId);cst.setInt(2, num);cst.execute();mit(); catch (SQLException e1) try conn.rollback();JOptionPane.showMessageDialog(new TestFrame(), 客户订票失败!); catch (SQLException e2) JOptionPane.showMessageDialog(new TestFrame(), 客户订票失败!); finally if (cst != null) try cst.close(); catch

32、(SQLException e1) e1.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e1) e1.printStackTrace();/* * 订票时更新数据库中的用户表 */private void UpdateUser() String tId=ftid.getText();String bId=fbodyId.getText();String cID=fche.getText();String pwd=String.valueOf(jpField.getPassword();int

33、num=0;if(bId.equals(EnterFrame.ID)&(pwd.equals(EnterFrame.password)if(fzhangshu.getText().length()0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgbc.getconnect();Statement cst = null;try cst = conn.createStatement();cst.executeUpdate(insert into order_table(tid,id_number,t_num,train

34、sum)+ values(+ tId+ ,+ bId+ ,+ cID + ,+num+);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 !=

35、 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 java.awt.event

36、.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.JPanel;imp

37、ort 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 JTextField(9);J

38、TextArea 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,GridBagConstraints.NONE, GridBagConstra

39、ints.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(), con);con = getGridBag

40、Constraints(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( 车 次 );JLabel dateLabel = new JLabel( 日 期 );JLabel stationLabel = new JLabel( 起点站 );JLabel zhiLabel = new JLabel( 终点站 );JLabel l1 = new JLabel( );JLabel l2 = new JLabel( );JButton checkButton = new JButton(查

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服