importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.*;importjavax.swing.*;importjavax.swing.border.TitledBorder;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassTrainInformationQueryextendsJFrame{privateContainerfile;privateComponentopen;publicTrainInformationQuery(){JPanelp1=newJPanel(newFlowLayout(FlowLayout.CENTER));JPanelp2=newJPanel(newFlowLayout(FlowLayout.CENTER));JPanelp3=newJPanel(newFlowLayout(FlowLayout.CENTER));JPanelp4=newJPanel();JLabeljlb1=newJLabel(火车站列车时刻表);JLabeljlb2=newJLabel(车次);finalJTextFieldjtf=newJTextField(8);JButtonjbt1=newJButton(查询);JButtonjbt2=newJButton(全部火车信息);finalJTextAreajta=newJTextArea(10,30);p1.add(jlb1);p2.add(jta);p2.setBorder(newTitledBorder());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(newTitledBorder());add(p4);//查询按钮finalJPanelpanel=newJPanel();jbt1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){JFileChooseropenfile=newJFileChooser();openfile.setDialogTitle(打开文件);openfile.setApproveButtonText(打开);openfile.showOpenDialog(panel);Filefilename=openfile.getSelectedFile();StringBufferstrBF=newStringBuffer();Stringerror_message=Error;FileInputStreaminputfile=null;try{charbuffer[]=newchar[1024];inputfile=newFileInputStream(filename);intlen=0;//如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中FileReaderin=newFileReader(filename.getAbsoluteFile());while((len=in.read(buffer))!=-1){strBF.append(buffer,0,len);}inputfile.close();//文本框对象text使用函数setText将StringBuffer的String写入文本框中jta.setText(strBF.toString());Stringopenfilename=filename.getName();setTitle(openfilename);}catch(IOExceptionioEX){JOptionPane.showMessageDialog(panel,error_message);}}});//查询全部火车信息按钮finalJPanelpanel1=newJPanel();jbt2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente2){JFileChooseropenfile=newJFileChooser();openfile.setDialogTitle(打开文件);openfile.setApproveButtonText(打开);openfile.showOpenDialog(panel1);Filefilename=openfile.getSelectedFile();StringBufferstrBF=newStringBuffer();Stringerror_message=Error;FileInputStreaminputfile=null;try{charbuffer[]=newchar[1024];inputfile=newFileInputStream(filename);intlen=0;//如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中FileReaderin=newFileReader(filename.getAbsoluteFile());while((len=in.read(buffer))!=-1){strBF.append(buffer,0,len);}inputfile.close();//文本框对象text使用函数setText将StringBuffer的String写入文本框中jta.setText(strBF.toString());Stringopenfilename=filename.getName();setTitle(openfilename);}catch(IOExceptionioEX){JOptionPane.showMessageDialog(panel1,error_message);}}});}publicstaticvoidmain(String[]args){TrainInformationQueryq=newTrainInformationQuery();q.setTitle(始发列车时刻表);q.setSize(500,400);q.setVisible(true);}}classZhuceextendsJFrame{protectedstaticfinalStringPath=null;publicZhuce(){JLabeljlb1=newJLabel(旅客注册信息);JLabeljlb2=newJLabel(姓名);JLabeljlb3=newJLabel(密码);JLabeljlb4=newJLabel(性别);JLabeljlb5=newJLabel(身份证号);JLabeljlb6=newJLabel(工作);JLabeljlb7=newJLabel(电话);finalJTextFieldjtf1=newJTextField(10);finalJTextFieldjtf2=newJTextField(10);finalJTextFieldjtf3=newJTextField(10);finalJTextFieldjtf4=newJTextField(10);finalJTextFieldjtf5=newJTextField(10);finalJTextFieldjtf6=newJTextField(10);JButtonjbt1=newJButton(注册);JPanelp1=newJPanel(newFlowLayout(FlowLayout.LEFT,10,20));JPanelp2=newJPanel(newGridLayout(7,2,10,10));JPanelp3=newJPanel(newBorderLayout(5,5));p2.add(jlb2);p2.add(jtf1);p2.add(jlb3);p2.add(jtf2);p2.add(jlb4);p2.add(jtf3);p2.add(jlb5);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(newActionListener(){publicvoidactionPerformed(ActionEvente){FileInputStreamfin;FileOutputStreamfout=null;Stringname=jtf1.getText();Stringpassword=jtf2.getText();Stringsex=jtf3.getText();Stringid=jtf4.getText();Stringjob=jtf5.getText();Stringtel=jtf6.getText();try{Filef=newFile(e:\\cgj\\myfile.txt);BufferedWriterbr=newBufferedWriter(newFileWriter(f));br.write(name);br.write(password);br.write(sex);br.write(id);br.write(job);br.write(tel);br.flush();br.close();}catch(FileNotFoundExceptione1){e1.printStackTrace();}catch(IOExceptione1){e1.printStackTrace();}JOptionPane.showMessageDialog(null,恭喜您,注册成功!);}privatevoidreadTextFile(Stringpath){StringfilePath=e:\\cgj\\myfile.txt;readTextFile(Path);}});}publicstaticvoidmain(String[]args){Zhucez=newZhuce();z.setTitle(火车票订票系统);z.setSize(250,300);z.setVisible(true);}}classTicketQueryextendsJFrame{publicTicketQuery(){JPanelp1=newJPanel(newFlowLayout(FlowLayout.LEFT,5,5));JPanelp2=newJPanel();JLabeljlb=newJLabel(请输入旅客姓名:);finalJTextFieldjtf=newJTextField(12);JButtonjbt=newJButton(查询);JButtonjbt3=newJButton(退票)