public class BaseFrame extends JFrame{
public BaseFrame(){
this.setSize(800, 600);
this.setUndecorated(true);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
}
}
public class MainFrame extends BaseFrame implements ActionListener{
JButton buybutton;
JButton checkbutton;
JButton rebutton;
JButton backbutton;
public MainFrame(){
setTitle("购票系统");
FrameBackground.setBG(this, "img/bg1.jpg");
buybutton=new CustomButton(150,450,"购票",CustomButton.LEFT);
checkbutton=new CustomButton(500,450,"值机",CustomButton.RIGHT);
rebutton=new CustomButton(150,500,"退票/改签",CustomButton.LEFT);
backbutton=new CustomButton(500,500,"退出系统",CustomButton.RIGHT);
buybutton.addActionListener(this);
checkbutton.addActionListener(this);
rebutton.addActionListener(this);
backbutton.addActionListener(this);
add(buybutton);
add(checkbutton);
add(rebutton);
add(backbutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s= e.getActionCommand();
if(s.equals("购票")){
BuyFrame buyframe=new BuyFrame();
buyframe.setVisible(true);
}
if(s.equals("值机")){
CheckFrame checkframe=new CheckFrame();
checkframe.setVisible(true);
}
if(s.equals("退票/改签")){
ReFrame reFrame=new ReFrame();
reFrame.setVisible(true);
}
if(s.equals("退出系统")){
System.exit(0);
}
}
public static void main(String[] args) {
MainFrame mf=new MainFrame();
mf.setVisible(true);
}
}
public class BuyFrame extends BaseFrame implements ActionListener{
JLabel startLabel;
JLabel endLabel;
JLabel IDLabel;
JLabel nameLabel;
JLabel flightLabel;
JLabel startdateLabel;
JComboBox<String> startComboBox;
JComboBox<String> endComboBox;
JTextField IDtextfield;
JTextField nametextfield;
JTextField flighttextfield;
JTextField startdatetextfield;
String[] startname;
String[] endname;
JButton backbutton;
JButton paybutton;
BuyFrame(){
this.setTitle("购票界面");
FrameBackground.setBG(this, "img/bg2.jpg");
startname= new String[]{"大连","北京","上海","广州","深圳","成都","昆明","哈尔滨","长春","沈阳","天津","西安","乌鲁木齐","郑州","武汉","无锡","南京","温州","重庆","三亚","厦门","长沙","青岛","杭州"};
endname= new String[]{"大连","北京","上海","广州","深圳","成都","昆明","哈尔滨","长春","沈阳","天津","西安","乌鲁木齐","郑州","武汉","无锡","南京","温州","重庆","三亚","厦门","长沙","青岛","杭州"};
startLabel=new JLabel("startadderss");
startLabel.setHorizontalAlignment(SwingConstants.RIGHT);
startLabel.setBounds(250, 100, 80, 30);
startComboBox=new JComboBox<String>(startname);
startComboBox.setBounds(350, 100, 200, 30);
this.add(startLabel);
this.add(startComboBox);
endLabel=new JLabel("endadderss");
endLabel.setHorizontalAlignment(SwingConstants.RIGHT);
endLabel.setBounds(250, 150, 80, 30);
endComboBox=new JComboBox<String>(endname);
endComboBox.setBounds(350, 150, 200, 30);
this.add(endLabel);
this.add(endComboBox);
IDLabel=new JLabel("IDNumber");
IDLabel.setHorizontalAlignment(SwingConstants.RIGHT);
IDLabel.setBounds(250, 200, 80, 30);
IDtextfield=new JTextField();
IDtextfield.setBounds(350, 200, 200, 30);
this.add(IDLabel);
this.add(IDtextfield);
nameLabel=new JLabel("Name");
nameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
nameLabel.setBounds(250, 250, 80, 30);
nametextfield=new JTextField();
nametextfield.setBounds(350, 250, 200, 30);
this.add(nameLabel);
this.add(nametextfield);
flightLabel=new JLabel("Flight");
flightLabel.setHorizontalAlignment(SwingConstants.RIGHT);
flightLabel.setBounds(250, 300, 80, 30);
flighttextfield=new JTextField();
flighttextfield.setBounds(350,300, 200, 30);
this.add(flightLabel);
this.add(flighttextfield);
flighttextfield.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Ticket ticket=new Ticket();
ticket.setStartaddress(startname[startComboBox.getSelectedIndex()]);
ticket.setEndaddress(endname[endComboBox.getSelectedIndex()]);
SelsctFlight selectflight=new SelsctFlight(ticket,flighttextfield);
selectflight.setVisible(true);
}
});
startdateLabel=new JLabel("StartDate");
startdateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
startdateLabel.setBounds(250,350, 80, 30);
startdatetextfield=new JTextField();
startdatetextfield.setBounds(350,350, 200, 30);
this.add(startdateLabel);
this.add(startdatetextfield);
CalendarPanel calendar = new CalendarPanel(startdatetextfield, "yyyy-MM-dd HH:mm:ss");
calendar.initCalendarPanel();
this.add(calendar);
backbutton=new CustomButton(150,500,"返回",CustomButton.LEFT);
paybutton=new CustomButton(500,500,"购票",CustomButton.RIGHT);
backbutton.addActionListener(this);
paybutton.addActionListener(this);
this.add(backbutton);
this.add(paybutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("购票")){
boolean sigh=true;
String startAddress = startname[startComboBox.getSelectedIndex()];
String endAddress = endname[endComboBox.getSelectedIndex()];
String idnum = IDtextfield.getText();
String name = nametextfield.getText();
String startdate = startdatetextfield.getText();
if (startAddress.equals(endAddress)) {
JOptionPane.showMessageDialog(BuyFrame.this, "始发地和目的地不能相同!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(idnum)||!idnum.matches("\\d{18}")) {
JOptionPane.showMessageDialog(BuyFrame.this, "身份证号为空或输入错误,请重新填写身份证号!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(name)) {
JOptionPane.showMessageDialog(BuyFrame.this, "姓名不能为空,请填写姓名!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(startdate)) {
JOptionPane.showMessageDialog(BuyFrame.this, "出行时间不能为空,请填写出行时间!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
if(sigh){
Ticket ticket=new Ticket();
ticket.setStartaddress(startname[startComboBox.getSelectedIndex()]);
ticket.setEndaddress(endname[endComboBox.getSelectedIndex()]);
ticket.setName(nametextfield.getText());
ticket.setStartdate(startdatetextfield.getText());
ticket.setIdNum(IDtextfield.getText());
ticket.setOrderNum(OrderUtil.generateOrderNo());
PayFrame payframe=new PayFrame(this,ticket);
payframe.setVisible(true);
}
}
}
}
public class SelsctFlight extends BaseFrame implements ActionListener{
JLabel tip;
JScrollPane scrollPane;
JTable checktable;
JButton backbutton,surebutton;
JTextField flighttf;
int selectedRow=-1;
String flights;
public SelsctFlight(Ticket ticket,JTextField flighttf){
this.setTitle("查询");
FrameBackground.setBG(this, "img/bg2.jpg");
this.flighttf=flighttf;
tip=new JLabel("航班列表:");
tip.setBounds(100, 50,300, 50);
tip.setHorizontalAlignment(SwingConstants.LEFT);
ArrayList<Flight> flightlist=DataOperateUtil.readFlightData();
ArrayList<Flight> resultlist=new ArrayList<Flight>();
for(Flight flight:flightlist){
if(flight.getStartaddress().equals(ticket.getStartaddress())&flight.getEndaddress().equals(ticket.getEndaddress())) {
resultlist.add(flight);
}
}
Vector columnNames=new Vector();
columnNames.add("航班号");
columnNames.add("始发地");
columnNames.add("目的地");
columnNames.add("出发时间");
columnNames.add("到达时间");
columnNames.add("航空公司");
columnNames.add("机型");
columnNames.add("价格");
Vector tableValues=new Vector();
for(Flight flight:resultlist) {
Vector row=new Vector();
row.add(flight.getFlight());
row.add(flight.getStartaddress());
row.add(flight.getEndaddress());
row.add(flight.getStarttime());
row.add(flight.getEndtime());
row.add(flight.getPlant());
row.add(flight.getShape());
row.add(flight.getPrice());
tableValues.add(row);
}
DefaultTableModel tableModel=new DefaultTableModel(tableValues,columnNames);
checktable=new JTable(tableModel);
checktable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
checktable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
selectedRow=checktable.getSelectedRow();
flights=(String)tableModel.getValueAt(selectedRow, 0);
}
});
scrollPane=new JScrollPane();
scrollPane.setBounds(100, 100, 600, 350);
scrollPane.setViewportView(checktable);
backbutton=new CustomButton(150, 450,"返回",CustomButton.LEFT);
surebutton=new CustomButton(500, 450,"确认",CustomButton.RIGHT);
backbutton.addActionListener(this);
surebutton.addActionListener(this);
this.add(tip);
this.add(scrollPane);
this.add(backbutton);
this.add(surebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("确认")){
if(selectedRow==-1) {
JOptionPane.showMessageDialog(SelsctFlight.this, "请选择航班!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}else {
this.setVisible(false);
flighttf.setText(flights);
}
}
}
}
public class PayFrame extends BaseFrame implements ActionListener{
JRadioButton way1,way2,way3;
JButton backbutton,surebutton;
boolean visible;
JFrame buyframe;
Ticket ticket;
String selectedValue=null;
PayFrame(JFrame buyframe,Ticket ticket){
this.ticket=ticket;
this.buyframe=buyframe;
this.setTitle("支付界面");
FrameBackground.setBG(this, "img/bg2.jpg");
init();
}
public void init() {
way1=new JRadioButton("支付宝");
way1.setBounds(350,100,100,30);
this.add(way1);
way1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JRadioButton temp=(JRadioButton)e.getSource();
if(temp.isSelected()){
selectedValue=temp.getText();
}
}
});
way2=new JRadioButton("微信");
way2.setBounds(350,150,100,30);
this.add(way2);
way2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JRadioButton temp=(JRadioButton)e.getSource();
if(temp.isSelected()){
selectedValue=temp.getText();
}
}
});
way3=new JRadioButton("银行卡");
way3.setBounds(350,200,100,30);
this.add(way3);
way3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JRadioButton temp=(JRadioButton)e.getSource();
if(temp.isSelected()){
selectedValue=temp.getText();
}
}
});
backbutton=new CustomButton(150,450,"返回",CustomButton.LEFT);
surebutton=new CustomButton(500,450,"支付",CustomButton.RIGHT);
backbutton.addActionListener(this);
surebutton.addActionListener(this);
this.add(backbutton);
this.add(surebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("支付")){
if (selectedValue.equals("支付宝")) {
JOptionPane.showMessageDialog(this, "支付宝支付成功!",
"支付宝支付成功!", JOptionPane.ERROR_MESSAGE);
}
if (selectedValue.equals("微信")) {
JOptionPane.showMessageDialog(this, "微信支付成功!",
"微信支付成功!", JOptionPane.ERROR_MESSAGE);
}
if (selectedValue.equals("银行卡")) {
JOptionPane.showMessageDialog(this, "银行卡支付成功!",
"银行卡支付成功!", JOptionPane.ERROR_MESSAGE);
}
this.setVisible(false);
buyframe.setVisible(false);
ArrayList<Ticket> ticketlist=DataOperateUtil.readTicketData();
ticketlist.add(ticket);
DataOperateUtil.writeTicketData(ticketlist);
BuyFrame buyframe=new BuyFrame();
buyframe.setVisible(true);
}
}
}
public class CheckFrame extends BaseFrame implements ActionListener{
JLabel tipLabel;
JTextField checktext;
JButton backbutton,surebutton;
CheckFrame(){
this.setTitle("值机界面");
FrameBackground.setBG(this, "img/bg2.jpg");
tipLabel=new JLabel("请输入您购票时的订单号或乘机人的身份证号:");
tipLabel.setHorizontalAlignment(SwingConstants.LEFT);
tipLabel.setBounds(250, 100,300, 30);
checktext=new JTextField();
checktext.setBounds(250, 150,200, 30);
backbutton=new CustomButton(150, 450,"返回",CustomButton.LEFT);
surebutton=new CustomButton(500, 450,"确认",CustomButton.RIGHT);
backbutton.addActionListener(this);
surebutton.addActionListener(this);
this.add(tipLabel);
this.add(checktext);
this.add(backbutton);
this.add(surebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("确认")){
if(checktext.getText().equals(" "))
{
JOptionPane.showMessageDialog(this,"请输入身份证号或订单号!","请输入", JOptionPane.ERROR_MESSAGE);
return ;
}
Checking checking=null;
try {
checking = new Checking(checktext.getText());
} catch (IOException e1) {
e1.printStackTrace();
}
checking.setVisible(true);
}
}
}
public class Checking extends BaseFrame implements ActionListener{
JLabel tip;
JScrollPane scrollPane;
JTable checktable;
JButton backbutton,surebutton;
Ticket ticket;
public Checking(String string) throws IOException{
this.setTitle("查询");
FrameBackground.setBG(this, "img/bg2.jpg");
tip=new JLabel("购票订单列表:");
tip.setBounds(100, 50,300, 50);
tip.setHorizontalAlignment(SwingConstants.LEFT);
ArrayList<Ticket> resultlist=new ArrayList<Ticket>();
ArrayList<Ticket> ticketlist=DataOperateUtil.readTicketData();
for(Ticket ticket:ticketlist){
if(ticket.getIdNum().equals(string)|ticket.getOrderNum().equals(string)) {
resultlist.add(ticket);
}
}
Vector columnNames=new Vector();
columnNames.add("订单号");
columnNames.add("始发地");
columnNames.add("目的地");
columnNames.add("乘机人");
columnNames.add("身份证号");
columnNames.add("日期");
Vector tableValues=new Vector();
for(Ticket ticket:resultlist) {
Vector row=new Vector();
row.add(ticket.getOrderNum());
row.add(ticket.getStartaddress());
row.add(ticket.getEndaddress());
row.add(ticket.getName());
row.add(ticket.getIdNum());
row.add(ticket.getStartdate());
tableValues.add(row);
}
checktable=new JTable(tableValues,columnNames);
scrollPane=new JScrollPane();
scrollPane.setBounds(100, 100, 600, 350);
scrollPane.setViewportView(checktable);
backbutton=new CustomButton(150, 500,"返回",CustomButton.LEFT);
surebutton=new CustomButton(500, 500,"确认",CustomButton.RIGHT);
backbutton.addActionListener(this);
surebutton.addActionListener(this);
this.add(tip);
this.add(scrollPane);
this.add(backbutton);
this.add(surebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("确认")){
JOptionPane.showMessageDialog(Checking.this,"选坐成功!","生成订单号", JOptionPane.ERROR_MESSAGE);
Checking.this.setVisible(false);
}
}
}
public class ReFrame extends BaseFrame implements ActionListener{
JLabel tipLabel;
JTextField checktext;
JButton backbutton,surebutton;
ReFrame(){
this.setTitle("退票/改签界面");
FrameBackground.setBG(this, "img/bg2.jpg");
tipLabel=new JLabel("请输入您购票时的订单号或乘机人的身份证号:");
tipLabel.setBounds(250, 100, 200, 30);
checktext=new JTextField();
checktext.setBounds(250, 150,200, 30);
backbutton=new CustomButton(150, 450,"返回",CustomButton.LEFT);
surebutton=new CustomButton(500, 450,"确认",CustomButton.RIGHT);
backbutton.addActionListener(this);
surebutton.addActionListener(this);
this.add(tipLabel);
this.add(checktext);
this.add(backbutton);
this.add(surebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("确认")){
Reing re=new Reing(checktext.getText());
re.setVisible(true);
}
}
}
public class Reing extends BaseFrame implements ActionListener{
JLabel tip;
JScrollPane scrollPane;
JTable checktable;
JButton backbutton,refundbutton,changebutton;
public Reing(String string){
this.setTitle("查询");
FrameBackground.setBG(this, "img/bg2.jpg");
tip=new JLabel("购票订单列表:");
tip.setBounds(100, 50,300, 50);
tip.setHorizontalAlignment(SwingConstants.LEFT);
ArrayList<Ticket> resultlist=new ArrayList<Ticket>();
ArrayList<Ticket> ticketlist=DataOperateUtil.readTicketData();
for(Ticket ticket:ticketlist){
if(ticket.getIdNum().equals(string)|ticket.getOrderNum().equals(string)) {
resultlist.add(ticket);
}
}
Vector columnNames=new Vector();
columnNames.add("订单号");
columnNames.add("始发地");
columnNames.add("目的地");
columnNames.add("乘机人");
columnNames.add("身份证号");
columnNames.add("日期");
Vector tableValues=new Vector();
for(Ticket ticket:resultlist) {
Vector row=new Vector();
row.add(ticket.getOrderNum());
row.add(ticket.getStartaddress());
row.add(ticket.getEndaddress());
row.add(ticket.getName());
row.add(ticket.getIdNum());
row.add(ticket.getStartdate());
tableValues.add(row);
}
checktable=new JTable(tableValues,columnNames);
scrollPane=new JScrollPane();
scrollPane.setBounds(100, 100, 600, 350);
scrollPane.setViewportView(checktable);
backbutton=new CustomButton(100,500,"返回",CustomButton.LEFT);
refundbutton=new CustomButton(350,500,"退票",CustomButton.RIGHT);
changebutton=new CustomButton(530,500,"改签",CustomButton.RIGHT);
backbutton.addActionListener(this);
refundbutton.addActionListener(this);
changebutton.addActionListener(this);
this.add(tip);
this.add(scrollPane);
this.add(backbutton);
this.add(refundbutton);
this.add(changebutton);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("返回")){
this.dispose();
}
if(s.equals("退票")){
}
if(s.equals("改签")){
}
}
}