火车票售票系统源代码

阅读: 评论:0

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.io.FileWriter;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class TrainInformationQuery extends JFrame{
private Container file;
private Component open;
public TrainInformationQuery(){ 
JPanel p1=new JPanel(new FlowLayout(FlowLayout.CENTER));
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 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 = new JPanel();
jbt1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){     
JFileChooser openfile = new JFileChooser();
openfile.setDialogTitle("打开文件");
openfile.setApproveButtonText("打开");
openfile.showOpenDialog(panel);
File filename = SelectedFile();
StringBuffer strBF = new StringBuffer();
String error_message = "Error";
FileInputStream inputfile = null;
try {
char buffer[] = new char[1024];
inputfile = new FileInputStream(filename);
int len = 0;
// 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中
FileReader in = new AbsoluteFile());
while ((len = in.read(buffer)) != -1) {
strBF.append(buffer, 0, len);
}
inputfile.close();
// 文本框对象text使用函数setText将StringBuffer的String写入文本框中
jta.String());
String openfilename = Name();
setTitle(openfilename);    } catch (IOException ioEX) {
JOptionPane.showMessageDialog(panel, error_message
);
}  }
});
//查询全部火车信息按钮
final JPanel panel1 = new JPanel();
jbt2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e2){
JFileChooser openfile = new JFileChooser();
openfile.setDi
alogTitle("打开文件");
openfile.setApproveButtonText("打开");
openfile.showOpenDialog(panel1);
File filename = SelectedFile();
StringBuffer strBF = new StringBuffer();
String error_message = "Error";
FileInputStream inputfile = null;
try {
char buffer[] = new char[1024];
inputfile = new FileInputStream(filename);
int len = 0;
/
/ 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中
FileReader in = new AbsoluteFile());
while ((len = in.read(buffer)) != -1) {
strBF.append(buffer, 0, len);
}
inputfile.close();
// 文本框对象text使用函数setText将StringBuffer的String写入文本框中
jta.String());
String openfilename = Name();
setTitle(openfilename);    } catch (IOException ioEX) {
JOptionPane.showMessageDialog(panel1, error_message
)
;
}  }
});
}
public static void main(String[] args){
TrainInformationQuery q=new TrainInformationQuery();
q.setTitle("始发列车时刻表");
q.setSize(500,400);
q.setVisible(true);
}
}
class Zhuce extends JFrame{
protected static final String Path = null;
public Zhuce(){
JLabel jlb1=new JLabel("旅客注册信息");
JLabel jlb2=new JLabel(" 姓名 ");
JLabel jlb3=new JLabel(" 密码 ");
JLabel jlb4=new JLabel(" 性别 ");
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 JTextField 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(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(new ActionListener(){
public void actionPerformed(ActionEvent e){
FileInputStream fin;
FileOutputStream fout = null;
String Text();
String Text();
String Text();
String Text();
String Text();
String Text();
try {
File f=new File("e:\\cgj\\");
BufferedWriter br=new BufferedWriter(new FileWri
ter(f));
br.write(name);
br.write(password);
br.write(sex);
br.write(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:\\cgj\\";
readTextFile(Path);
}
}); 
}
public static void main(String[] args){
Zhuce z=new Zhuce();
z.setTitle("火车票订票系统");
z.setSize(250,300);
z.setVisible(true);
}
}
class TicketQuery extends JFrame{
public TicketQuery(){
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,5,5));
JPanel p2=new JPanel();
JLabel jlb=new JLabel("请输入旅客姓名:");
final JTextField jtf=new JTextField(12);
JButton 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 MESSAGE";
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));
JMenuBar Mbar = new JMenuBar();
this.setJMenuBar(Mbar);
JMenu file = new JMenu("文件");
Mbar.add(file);  JMenuItem open = new JMenuItem("打开");
open.setMnemonic('O');
open.KeyStroke('O',
java.awt.Event.CTRL_MASK, true));
jbt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser openfile = new JFileChooser();
openfile.setDialogTitle("打开文件");
openfile.setApproveButtonText("打开");
openfile.showOpenDialog(panel);
File filename = SelectedFile();
StringBuffer strBF = new StringBuffer();
String error_message = "Error";
FileInputStream inputfile = null;
try {
char buffer[] = new char[1024];
inputfile = new FileInputStream(filename);
int len = 0;
// 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中
FileReader in = new AbsoluteFile());
while ((len = in.read(buffer)) != -1) {
strBF.append(buffer, 0, len);
}
inputfile.close();
// 文本框对象text使用函数setText将StringBuffer的String写入文本框中
te
xt.String());
String openfilename = Name();
setTitle(openfilename);    } catch (IOException ioEX) {
JOptionPane.showMessageDialog(panel, error_message
);
}  }
});
file.add(open);
file.addSeparator();
//退票按钮
jbt3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
FileOutputStream testfile = null;
try {
testfile = new FileOutputStream(" e:\\cgj\\");
testfile.write(new String("").getBytes());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.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 extends JFrame{
String trainnum=null;
String dstation=null;
String ordernum;
String seattype1;
String seattype2;
String name;
String sql;
ResultSet rs;
String sstation=null;
int num,num1;
public DingPiao(){
JPanel p1=new JPanel(new GridLayout(2,1,5,5));
JPanel p2=new JPanel(new GridLayout(3,4,5,5));
JPanel p3=new JPanel(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 JRadioButton 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=new 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(jft3);
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 ActionListener(){
public void actionPerformed(ActionEvent e){
String Text();
String Text();
String seattype1=jrb1.isSelected()?"硬座":" ";
String seattype2=jrb2.isSelected()?"卧铺":" ";
String Text();
String sstation=jf
try {
File f=new File("e:\\cgj\\");
BufferedWriter br=new BufferedWriter(new FileWriter(f));
br.write(trainnum);
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.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){       
Text();
Text();
Text();
seattype1=jrb1.isSelected()?"硬座":" ";
seattype2=jrb2.isSelected()?"卧铺":" ";
Text();
Text();     
YuLan y=new YuLan();
y.setTitle("火车票订票系统");
y.setSize(500,250);
y.setVisible(true);   
}
});       
}
class YuLan extends JFrame{
public YuLan(){
JMenuBar 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 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("终点站: "+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 ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"请稍等,正在为您打印!");   
}
});     
}
public void main(String[] args){
YuLan y=new YuLan();
y.setTitle("火车票订票系统");
y.setSize(500,250);
y.setVisible(true);
}
}
public static void main(String[] args){
try
{
FileReader fr=new FileReader("e:\\cgj\\");
FileWriter fw=new FileWriter("e:\\cgj\\");
int ad();
while(b!=-1)
{
fw.write(b);
System.out.print((char)b);
ad();
}
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 JFrame{
public CustomLogin(){
JPanel p1=new JPanel(new FlowLayout(FlowLayout.CENTER,10,10));
JLabel jlb1=new JLabel("火车票管理系统");
p1.add(jlb1);
JPanel p2=new JPanel(new GridLa

本文发布于:2023-05-03 15:01:01,感谢您对本站的认可!

本文链接:http://www.035400.com/whly/3/375081.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:系统   火车票   信息   订票   文件   加入   文本框   查询
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2024-2030 Comsenz Inc.Powered by © 文化旅游网 滇ICP备2022007236号-403 联系QQ:1103060800网站地图