火车票售票系统源代码.docx

上传人:小飞机 文档编号:3639752 上传时间:2023-03-14 格式:DOCX 页数:29 大小:41.54KB
返回 下载 相关 举报
火车票售票系统源代码.docx_第1页
第1页 / 共29页
火车票售票系统源代码.docx_第2页
第2页 / 共29页
火车票售票系统源代码.docx_第3页
第3页 / 共29页
火车票售票系统源代码.docx_第4页
第4页 / 共29页
火车票售票系统源代码.docx_第5页
第5页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《火车票售票系统源代码.docx》由会员分享,可在线阅读,更多相关《火车票售票系统源代码.docx(29页珍藏版)》请在三一办公上搜索。

1、火车票售票系统源代码import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.*;import javax.swing.*;import javax.swing.border.TitledBorder;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java

2、.io.FileWriter;import java.io.IOException;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class TrainInformationQuery extends JFrameprivate Container file;private Component open;public TrainInformationQueryJPanel p1=new JPanel(new FlowLayout(FlowLayout.CENTER

3、);JPanel p2=new JPanel(new FlowLayout(FlowLayout.CENTER);JPanel p3=new JPanel(new FlowLayout(FlowLayout.CENTER);JPanel p4=new JPanel;JLabel jlb1=new JLabel(火车站列车时刻表);JLabel jlb2=new JLabel(车次);final JTextField jtf=new JTextField(8);JButton jbt1=new JButton(查询);JButton jbt2=new JButton(全部火车信息);final

4、JTextArea jta=new JTextArea(10,30);p1.add(jlb1);p2.add(jta);p2.setBorder(new TitledBorder( );p3.add(jlb2);p3.add(jtf);p3.add(jbt1);p3.add(jbt2);p4.add(p1,BorderLayout.NORTH);p4.add(p2,BorderLayout.CENTER);p4.add(p3,BorderLayout.SOUTH);p4.setBorder(new TitledBorder( );add(p4);/查询按钮final JPanel panel

5、= new JPanel;jbt1.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)JFileChooser openfile = new JFileChooser;openfile.setDialogTitle(打开文件);openfile.setApproveButtonText(打开);openfile.showOpenDialog(panel);File filename = openfile.getSelectedFile;StringBuffer strBF = new St

6、ringBuffer;String error_message = Error;FileInputStream inputfile = null;try char buffer = new char1024;inputfile = new FileInputStream(filename);int len = 0;/ 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中FileReader in = new FileReader(filename.getAbsoluteFile);while (len = in.read(buffer) != -1) st

7、rBF.append(buffer, 0, len);inputfile.close;/ 文本框对象text使用函数setText将StringBuffer的String写入文本框中jta.setText(strBF.toString);String openfilename = filename.getName;setTitle(openfilename); catch (IOException ioEX) JOptionPane.showMessageDialog(panel, error_message); );/查询全部火车信息按钮final JPanel panel1 = new J

8、Panel;jbt2.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e2)JFileChooser openfile = new JFileChooser;openfile.setDialogTitle(打开文件);openfile.setApproveButtonText(打开);openfile.showOpenDialog(panel1);File filename = openfile.getSelectedFile;StringBuffer strBF = new StringB

9、uffer;String error_message = Error;FileInputStream inputfile = null;try char buffer = new char1024;inputfile = new FileInputStream(filename);int len = 0;/ 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中FileReader in = new FileReader(filename.getAbsoluteFile);while (len = in.read(buffer) != -1) strBF.a

10、ppend(buffer, 0, len);inputfile.close;/ 文本框对象text使用函数setText将StringBuffer的String写入文本框中jta.setText(strBF.toString);String openfilename = filename.getName;setTitle(openfilename); catch (IOException ioEX) JOptionPane.showMessageDialog(panel1, error_message); );public static void main(String args)TrainI

11、nformationQuery q=new TrainInformationQuery;q.setTitle(始发列车时刻表);q.setSize(500,400);q.setVisible(true);class Zhuce extends JFrameprotected static final String Path = null;public ZhuceJLabel jlb1=new JLabel(旅客注册信息);JLabel jlb2=new JLabel( 姓名 );JLabel jlb3=new JLabel( 密码 );JLabel jlb4=new JLabel( 性别 );

12、JLabel jlb5=new JLabel( 身份证号);JLabel jlb6=new JLabel( 工作);JLabel jlb7=new JLabel( 电话);final JTextField jtf1=new JTextField(10);final JTextField jtf2=new JTextField(10);final JTextField jtf3=new JTextField(10);final JTextField jtf4=new JTextField(10);final JTextField jtf5=new JTextField(10);final JTe

13、xtField jtf6=new JTextField(10);JButton jbt1=new JButton( 注 册 );JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,20);JPanel p2=new JPanel(new GridLayout(7,2,10,10);JPanel p3=new JPanel(new BorderLayout(5,5);p2.add(jlb2);p2.add(jtf1);p2.add(jlb3);p2.add(jtf2);p2.add(jlb4);p2.add(jtf3);p2.add(jl

14、b5);p2.add(jtf4);p2.add(jlb6);p2.add(jtf5);p2.add(jlb7);p2.add(jtf6);p2.add(jbt1);p3.add(p1,BorderLayout.NORTH);p3.add(p2,BorderLayout.CENTER);add(p3,BorderLayout.CENTER);jbt1.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)FileInputStream fin;FileOutputStream fout = nu

15、ll;String name=jtf1.getText;String password=jtf2.getText;String sex=jtf3.getText;String id=jtf4.getText;String job=jtf5.getText;String tel=jtf6.getText;try File f=new File(e:cgjmyfile.txt);BufferedWriter br=new BufferedWriter(new FileWriter(f);br.write(name);br.write(password);br.write(sex);br.write

16、(id);br.write(job);br.write(tel);br.flush;br.close; catch (FileNotFoundException e1) e1.printStackTrace; catch (IOException e1)e1.printStackTrace;JOptionPane.showMessageDialog(null,恭喜您,注册成功!);private void readTextFile(String path) String filePath=e:cgjmyfile.txt;readTextFile(Path););public static vo

17、id main(String args)Zhuce z=new Zhuce;z.setTitle(火车票订票系统);z.setSize(250,300);z.setVisible(true);class TicketQuery extends JFramepublic TicketQueryJPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,5,5);JPanel p2=new JPanel;JLabel jlb=new JLabel(请输入旅客姓名:);final JTextField jtf=new JTextField(12);JBut

18、ton jbt=new JButton(查询);JButton jbt3=new JButton(退票);final JTextArea jta=new JTextArea(10,30);p1.add(jlb);p1.add(jtf);p1.add(jbt);p1.add(jbt3);add(p1,BorderLayout.SOUTH);p2.add(jta);add(p2);p2.setBorder(new TitledBorder(内容);/查询按钮/ 简单的布局String openFilePath;String openFileName;String title = ERROR MES

19、SAGE;int type = JOptionPane.ERROR_MESSAGE; final JTextArea text = new JTextArea;final JPanel panel = new JPanel;panel.setLayout(new GridLayout(1, 1);panel.add(new JScrollPane(text);this.getContentPane.add(panel); / 菜单项JMenuBar Mbar = new JMenuBar;this.setJMenuBar(Mbar);JMenu file = new JMenu(文件);Mba

20、r.add(file); JMenuItem open = new JMenuItem(打开);open.setMnemonic(O);open.setAccelerator(KeyStroke.getKeyStroke(O,java.awt.Event.CTRL_MASK, true);jbt.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)JFileChooser openfile = new JFileChooser;openfile.setDialogTitle(打开文件);op

21、enfile.setApproveButtonText(打开);openfile.showOpenDialog(panel);File filename = openfile.getSelectedFile;StringBuffer strBF = new StringBuffer;String error_message = Error;FileInputStream inputfile = null;try char buffer = new char1024;inputfile = new FileInputStream(filename);int len = 0;/ 如下为依次读取文件

22、中的每一行内容,将其加入StringBuffer数据类型便利strBF中FileReader in = new FileReader(filename.getAbsoluteFile);while (len = in.read(buffer) != -1) strBF.append(buffer, 0, len);inputfile.close;/ 文本框对象text使用函数setText将StringBuffer的String写入文本框中text.setText(strBF.toString);String openfilename = filename.getName;setTitle(o

23、penfilename); catch (IOException ioEX) JOptionPane.showMessageDialog(panel, error_message); );file.add(open);file.addSeparator;/退票按钮jbt3.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)FileOutputStream testfile = null;try testfile = new FileOutputStream( e:cgjmyfile.txt

24、);testfile.write(new String().getBytes); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace;JOptionPane.showMessageDialog(null,退票成功!););public static void main(String args)TicketQuery t=new TicketQuery;t.setTitle(火车票查询系统);t.setSize(400,250);t.setVisible(true);class DingPiao e

25、xtends JFrameString trainnum=null;String dstation=null;String ordernum;String seattype1;String seattype2;String name;String sql;ResultSet rs;String sstation=null;int num,num1;public DingPiaoJPanel p1=new JPanel(new GridLayout(2,1,5,5);JPanel p2=new JPanel(new GridLayout(3,4,5,5);JPanel p3=new JPanel

26、(new GridLayout(1,4,5,5);/JPanel p4=new JPanel(new GridLayout);JLabel jlb1=new JLabel(1 订票时间必须为三天以内的票);JLabel jlb2=new JLabel(2 本系统只属模拟不涉及票额的计算);JLabel jlb3=new JLabel(车次);JLabel jlb4=new JLabel(始发车站);JLabel jlb5=new JLabel(座位号);JLabel jlb6=new JLabel(终点站);ButtonGroup group=new ButtonGroup;final JRa

27、dioButton jrb1=new JRadioButton(硬座);final JRadioButton jrb2=new JRadioButton(卧铺);group.add(jrb1);group.add(jrb2);JLabel jlb9=new JLabel( );JLabel jlb8=new JLabel( );JLabel jlb10=new JLabel( 姓 名 );final JTextField jft1=new JTextField(8);final JTextField jft2=new JTextField(8);final JTextField jft3=ne

28、w JTextField(8);final JTextField jft4=new JTextField(8);final JTextField jft5=new JTextField(8);JButton jbt1=new JButton(打印预览); final JButton jbt3=new JButton( 订 票 );p1.add(jlb1);p1.add(jlb2);p1.setBorder(new TitledBorder(); p2.add(jlb3);p2.add(jft1); p2.add(jlb4);p2.add(jft2); p2.add(jlb5);p2.add(j

29、ft3);p2.add(jrb1); p2.add(jrb2);p2.add(jlb10);p2.add(jft4); p2.add(jlb6);p2.add(jft5); p3.add(jbt1); p3.add(jbt3);p3.add(jlb8);p3.add(jlb9);add(p1,BorderLayout.NORTH);add(p2,BorderLayout.CENTER);add(p3,BorderLayout.SOUTH); jbt3.addActionListener(new ActionListenerpublic void actionPerformed(ActionEv

30、ent e)String trainnum=jft1.getText;String dstation=jft2.getText;String seattype1=jrb1.isSelected?硬座: ;String seattype2=jrb2.isSelected?卧铺: ;String name=jft4.getText;String sstation=jft5.getText;try File f=new File(e:cgjdingpiao.txt);BufferedWriter br=new BufferedWriter(new FileWriter(f);br.write(tra

31、innum);br.write(dstation);br.write(seattype1);br.write(seattype2);br.write(name);br.write(sstation);br.flush;br.close; catch (FileNotFoundException e1) e1.printStackTrace; catch (IOException e1)e1.printStackTrace;jft3.setText(String.valueOf(num);JOptionPane.showMessageDialog(null,恭喜您!订票成功!); );jbt1.

32、addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)trainnum=jft1.getText;dstation=jft2.getText;ordernum=jft3.getText;seattype1=jrb1.isSelected?硬座: ;seattype2=jrb2.isSelected?卧铺: ;name=jft4.getText;sstation=jft5.getText;YuLan y=new YuLan;y.setTitle(火车票订票系统);y.setSize(500,25

33、0);y.setVisible(true);); class YuLan extends JFramepublic YuLanJMenuBar jmb=new JMenuBar;setJMenuBar(jmb);JMenu wen=new JMenu(文件); JMenuItem print=new JMenuItem(打印); jmb.add(wen);wen.add(print); JPanel p1=new JPanel(new GridLayout(2,1,5,5);JPanel p2=new JPanel(new GridLayout(3,2,5,5);JLabel jlb1=new

34、 JLabel(1 订票时间必须为三天以内的票);JLabel jlb2=new JLabel(2 本系统只属模拟不涉及票额的计算);p1.add(jlb1);p1.add(jlb2);add(p1,BorderLayout.NORTH);JLabel jlb3=new JLabel(座位号: +ordernum); JLabel jlb4=new JLabel(姓名: +name);JLabel jlb5=new JLabel(车次: +trainnum);JLabel jlb6=new JLabel(始发车站: +dstation); JLabel jlb7=new JLabel(终点站:

35、 +sstation);JLabel jlb8=new JLabel(座位类型: +seattype1+seattype2); p2.add(jlb3);p2.add(jlb5);p2.add(jlb4);p2.add(jlb6);p2.add(jlb7);p2.add(jlb8);add(p2,BorderLayout.CENTER);print.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)JOptionPane.showMessageDialog(null,请稍等,正在为您打印!

36、);); public void main(String args)YuLan y=new YuLan;y.setTitle(火车票订票系统);y.setSize(500,250);y.setVisible(true);public static void main(String args)tryFileReader fr=new FileReader(e:cgjjava.txt);FileWriter fw=new FileWriter(e:cgjjavaCopy.txt);int b=fr.read;while(b!=-1)fw.write(b);System.out.print(char

37、)b);b=fr.read;fw.close;fr.close;catch(Exception e)e.printStackTrace;DingPiao d=new DingPiao;d.setTitle(火车票订票系统);d.setSize(500,250);d.setVisible(true);class CustomLogin extends JFramepublic CustomLoginJPanel p1=new JPanel(new FlowLayout(FlowLayout.CENTER,10,10);JLabel jlb1=new JLabel(火车票管理系统);p1.add(

38、jlb1);JPanel p2=new JPanel(new GridLayout(5,1,10,10);JButton jbt1=new JButton(剩余车票查询);JButton jbt2=new JButton( 订 票 );JButton jbt3=new JButton(订票信息查询);p2.add(jbt1);p2.add(jbt2);p2.add(jbt3);ImageIcon usIcon = new ImageIcon(image/flower.gif);JLabel jlb2=new JLabel(usIcon);JPanel p3=new JPanel(new Flo

39、wLayout);p3.add(jlb2);JPanel p4=new JPanel(new BorderLayout);p4.add(p1,BorderLayout.NORTH);p3.add(p2,BorderLayout.EAST);p4.add(p3,BorderLayout.CENTER);add(p4,BorderLayout.CENTER);jbt1.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)TrainInformationQuery q=new TrainInfor

40、mationQuery;q.setTitle(始发车时刻表查询);q.setSize(500,400);q.show;);jbt2.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)DingPiao d=new DingPiao;d.setTitle(订票);d.setSize(450,230);d.show;);jbt3.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)Ticket

41、Query t=new TicketQuery;t.setTitle(订票信息查询);t.setSize(500,250);t.show;);public static void main(String args)CustomLogin c=new CustomLogin;c.setTitle(火车站订票系统);c.setSize(400,250);c.setVisible(true);class Custom extends JFramepublic CustomJPanel p1=new JPanel;p1.setLayout(new FlowLayout(FlowLayout.CENTE

42、R,10,10);JLabel jlb2=new JLabel( 用户名: );final JTextField jtfName=new JTextField(10);JLabel jlb3=new JLabel( 密 码: );final JPasswordField jtfScret=new JPasswordField(10);JButton jbt1=new JButton(登 录);JButton jbt2=new JButton(注 册);p1.add(jlb2);p1.add(jtfName); p1.add(jlb3);p1.add(jtfScret); p1.add(jbt1

43、);p1.add(jbt2);JPanel p2=new JPanel(new FlowLayout(FlowLayout.CENTER,10,10);JPanel p3=new JPanel(new BorderLayout);JLabel jlb1=new JLabel(火车票管理系统);p2.add(jlb1);p3.add(p2,BorderLayout.NORTH);p3.add(p1,BorderLayout.CENTER);add(p3,BorderLayout.CENTER);jbt1.addActionListener(new ActionListenerpublic voi

44、d actionPerformed(ActionEvent e)String jtfname=jack;String scret=1234;if(jtfname.equals()|!scret.equals()setVisible(false);CustomLogin c=new CustomLogin;c.setTitle(火车站订票系统);c.setSize(400,300);c.show;elseJOptionPane.showMessageDialog(null,对不起,您的用户名或密码错误);JOptionPane.showMessageDialog(null,输入不能为空););jbt2.addActionListener(new ActionListenerpublic void actionPerformed(ActionEvent e)Zhuce z=new Zhuce;z.setTitle(信息注册);z.setSize(250,300);z.show;);public static void main(String args)C

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

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号