火车票售票系统源代码.docx
《火车票售票系统源代码.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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 火车票 售票 系统 源代码

链接地址:https://www.31ppt.com/p-3639752.html