1、要求:
(1)设计每条航线所涉及的信息,如终点站名、航班号、飞机号、飞机周日(星期几)、乘员定额、余票量、订定票的客户名单(包括姓名、订票量、舱位等级1,2或3)等;
(2)结合基本操作的单链表、队列、二叉树等数据结构以及排序算法,设计机票系统的查询、订票、退票等功能;
(3)设计并实现人机交互友好的界面或菜单。
2、运行情况:
















3、源代码

(1)RegisterFrame

package Plane;import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;public class RegisterFrame extends JFrame implements ActionListener {BufferedReader br = null;JComboBox<String> jcb = null;JLabel accountNumberJlb = null;JTextField accountNumberJtf = null;JPasswordField jpf = null;JButton dlgJbt = null;JRadioButton yesRemJrb = null;boolean isRegist = false;RegisterFrame() {RegisterPanel rpl = new RegisterPanel();Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();Image img = Toolkit.getDefaultToolkit().getImage("graph//RegisterIcon.jpg");JLabel jlb = new JLabel("欢迎选择璐璐航空");accountNumberJlb = new JLabel("账号");JLabel passwordJlb = new JLabel("密码");jpf = new JPasswordField();accountNumberJtf = new JTextField();jcb = new JComboBox<String>();dlgJbt = new JButton("登陆");yesRemJrb = new JRadioButton("记住密码");rpl.setLayout(null);jlb.setForeground(Color.red);jlb.setFont(new Font("楷体", Font.BOLD, 35));jlb.setSize(300, 50);jlb.setLocation(50, 5);rpl.add(jlb);accountNumberJlb.setFont(new Font("楷体", Font.BOLD, 25));accountNumberJlb.setSize(60, 25);accountNumberJlb.setLocation(10, 90);rpl.add(accountNumberJlb);passwordJlb.setFont(new Font("楷体", Font.BOLD, 25));passwordJlb.setSize(60, 25);passwordJlb.setLocation(10, 150);rpl.add(passwordJlb);jcb.setLocation(220, 90);jcb.setSize(130, 25);jcb.setFont(new Font("楷体", Font.BOLD, 20));jcb.addActionListener(this);Enumeration<String> keys = IOInfo.accountInfo.keys();while (keys.hasMoreElements()) {jcb.addItem(keys.nextElement());}rpl.add(jcb);accountNumberJtf.setSize(120, 25);accountNumberJtf.setLocation(80, 90);accountNumberJtf.setFont(new Font("楷体", Font.BOLD, 20));rpl.add(accountNumberJtf);jpf.addActionListener(this);jpf.setSize(120, 25);jpf.setLocation(80, 150);jpf.setFont(new Font("", Font.BOLD, 20));rpl.add(jpf);dlgJbt.setFont(new Font("楷体", Font.BOLD, 35));dlgJbt.setLocation(110, 190);dlgJbt.setForeground(Color.blue);dlgJbt.setSize(200, 40);dlgJbt.addActionListener(this);rpl.add(dlgJbt);yesRemJrb.setLocation(240, 155);yesRemJrb.setSize(80, 25);yesRemJrb.addActionListener(this);rpl.add(yesRemJrb);this.setIconImage(img);this.setLocation((int) ((screenSize.getWidth() - 400) / 2), (int) ((screenSize.getHeight() - 300) / 3));this.add(rpl);this.setSize(400, 300);this.setTitle("璐璐航空登陆界面");this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);}boolean ifRegist() {return isRegist;}private class RegisterPanel extends JPanel {RegisterPanel() {this.setSize(400, 300);}public void paintComponent(Graphics g) {Image img = new ImageIcon("graph//Register.jpg").getImage();g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);}}@Overridepublic void actionPerformed(ActionEvent e) {String isRem = null;if (e.getSource() == dlgJbt) {String accountNumberStr = accountNumberJtf.getText();String password = (IOInfo.accountInfo.get(accountNumberStr).split(" "))[0];if (password.equals(new String(jpf.getPassword()))) {isRegist = true;javax.swing.JOptionPane.showMessageDialog(null, "恭喜您,登陆成功!");this.dispose();try {new ClientFrame();} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}} else {jpf.setText("");javax.swing.JOptionPane.showMessageDialog(null, "密码错误,请重新输入!");}dlgJbt.setFocusable(false);} else if (e.getSource() == jcb) {jpf.setText("");accountNumberJtf.setText((String) jcb.getSelectedItem());if (1 == Integer.parseInt(IOInfo.accountInfo.get((String) jcb.getSelectedItem()).split(" ")[1])) {jpf.setText(IOInfo.accountInfo.get((String) jcb.getSelectedItem()).split(" ")[0]);yesRemJrb.setSelected(true);}else yesRemJrb.setSelected(false);} else if (yesRemJrb == e.getSource()) {   StringBuffer sb = new StringBuffer(IOInfo.accountInfo.get((String) jcb.getSelectedItem()));if (yesRemJrb.isSelected())sb.setCharAt(7 ,'1');elsesb.setCharAt(7, '0');IOInfo.accountInfo.put((String) jcb.getSelectedItem(), new String(sb));IOInfo.printInfo();}}public static void main(String[] args) throws Exception {new RegisterFrame();}
}

(2)MainPanel

package Plane;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class MainPanel extends JPanel implements ActionListener {// 主界面按钮JButton reServejbt = new JButton("机票预定");JButton findjbt = new JButton("预约查询");JButton changejbt = new JButton("退票改签");public static Selection flag = Selection.mainPanel;public MainPanel() {this.setSize(800, 600);this.setLayout(null);// 初始化标题JLabel welJlb = new JLabel("璐璐航空选票系统");this.add(welJlb);welJlb.setFont(new Font("楷体", Font.BOLD, 40));welJlb.setSize(500, 100);welJlb.setLocation(230, 20);welJlb.setForeground(new Color(0, 255, 255, 255));setButton();}void setButtonContent(JButton jbt, Font buttonFont, int x, int y) {this.add(jbt);jbt.setFocusable(false);jbt.setFont(buttonFont);jbt.setSize(120, 50);jbt.setLocation(x, y);jbt.addActionListener(this);}public void setButton() {Font buttonFont = new Font("楷体", Font.BOLD, 20);setButtonContent(reServejbt, buttonFont, 110, 480);setButtonContent(findjbt, buttonFont, 320, 480);setButtonContent(changejbt, buttonFont, 530, 480);}public void paintComponent(Graphics g) {Image img = new ImageIcon("graph//MainGraph.jpg").getImage();g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);}public void actionPerformed(ActionEvent e) {if (reServejbt == e.getSource()) flag = Selection.reServePanel;else if(e.getSource() == findjbt)flag = Selection.findPanel;else if(e.getSource() == changejbt)flag = Selection.changePanel;}
}

(3)ReservePanel

package Plane;import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.*;import javax.swing.*;public class ReservePanel extends JPanel implements ActionListener {int time = 0;int thisTime = 0;JButton returnJbt = new JButton("返回");JButton buyJbt = new JButton("购买");JLabel departureJlb = new JLabel("出发城市");JLabel destinationJlb = new JLabel("目的城市");JLabel departureDateJlb = new JLabel("出发日期");JLabel personNumJlb = new JLabel("出发人数");JLabel welJlb = new JLabel("机票预定");JRadioButton jrb = null;JComboBox<String> departureJcb = new JComboBox<String>();JComboBox<String> destinationJcb = new JComboBox<String>();JComboBox<String> departureMonthJcb = new JComboBox<String>();JComboBox<String> departureDayJcb = new JComboBox<String>();JComboBox<String> personNumJcb = new JComboBox<String>();Hashtable<String, String> jcbContent = new Hashtable<String, String>();Hashtable<JRadioButton, JLabel> ticketChoice = null;final int[] monthDayNum = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };String thisMonth = null;String thisDay = null;String ticketkey = null;public ReservePanel() {Init();}void Init() {this.setSize(800, 600);this.setLayout(null);this.setVisible(true);this.add(welJlb);this.add(returnJbt);this.add(buyJbt);welJlb.setFont(new Font("楷体", Font.BOLD, 40));welJlb.setSize(500, 100);welJlb.setLocation(320, 20);welJlb.setForeground(Color.yellow);returnJbt.addActionListener(this);returnJbt.setFont(new Font("楷体", Font.BOLD, 20));returnJbt.setSize(80, 25);returnJbt.setLocation(680, 520);returnJbt.setFocusable(false);buyJbt.addActionListener(this);buyJbt.setFont(new Font("楷体", Font.BOLD, 30));buyJbt.setSize(100, 40);buyJbt.setLocation(350, 480);buyJbt.setFocusable(false);initJcb();setLabel();}void initJcb() {this.add(departureJcb);this.add(destinationJcb);this.add(departureMonthJcb);this.add(departureDayJcb);this.add(personNumJcb);departureJcb.setLocation(430, 100);departureJcb.setSize(150, 40);departureJcb.setFont(new Font("楷体", Font.BOLD, 30));departureJcb.addActionListener(this);destinationJcb.setLocation(430, 200);destinationJcb.setSize(150, 40);destinationJcb.setFont(new Font("楷体", Font.BOLD, 30));destinationJcb.addActionListener(this);departureMonthJcb.setLocation(430, 300);departureMonthJcb.setSize(75, 40);departureMonthJcb.setFont(new Font("楷体", Font.BOLD, 30));departureMonthJcb.addActionListener(this);departureDayJcb.setLocation(505, 300);departureDayJcb.setSize(75, 40);departureDayJcb.setFont(new Font("楷体", Font.BOLD, 30));departureDayJcb.addActionListener(this);personNumJcb.setLocation(430, 400);personNumJcb.setSize(150, 40);personNumJcb.setFont(new Font("楷体", Font.BOLD, 30));personNumJcb.addActionListener(this);// 初始化前两个下拉菜单Enumeration<String> keys = IOInfo.ticketKeys;while (keys.hasMoreElements()) {String tmp = keys.nextElement();jcbContent.put(tmp.split(" ")[0], tmp.split(" ")[1]);}keys = jcbContent.keys();while (keys.hasMoreElements()) {departureJcb.addItem(keys.nextElement());}jcbContent.clear();keys = IOInfo.ticketInfo.keys();while (keys.hasMoreElements()) {String tmp = keys.nextElement();jcbContent.put(tmp.split(" ")[1], tmp.split(" ")[0]);}keys = jcbContent.keys();while (keys.hasMoreElements()) {destinationJcb.addItem(keys.nextElement());}// 初始化日期SimpleDateFormat sdf = new SimpleDateFormat("MM DD");String tmp = sdf.format(new Date());thisMonth = String.valueOf(Integer.parseInt((tmp.split(" ")[0])));thisDay = String.valueOf(Integer.parseInt((tmp.split(" ")[1])));for (int i = Integer.parseInt((tmp.split(" ")[0])); i <= 12; i++) {departureMonthJcb.addItem(String.valueOf(i));}for (int i = 1; i <= 20; i++) {personNumJcb.addItem(String.valueOf(i));}}void setLabelContent(JLabel jlb, Font labelFont, int x, int y) {this.add(jlb);jlb.setForeground(Color.red);jlb.setFont(labelFont);jlb.setSize(200, 50);jlb.setLocation(x, y);}public void setLabel() {Font labelFont = new Font("楷体", Font.BOLD, 30);setLabelContent(departureJlb, labelFont, 200, 100);setLabelContent(destinationJlb, labelFont, 200, 200);setLabelContent(departureDateJlb, labelFont, 200, 300);setLabelContent(personNumJlb, labelFont, 200, 400);}public void paintComponent(Graphics g) {Image img = new ImageIcon("graph//ReserverIcon.jpg").getImage();g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);}public void actionPerformed(ActionEvent e) {if (e.getSource() == returnJbt) {MainPanel.flag = Selection.mainPanel;} else if (e.getSource() == departureMonthJcb) {departureDayJcb.removeAllItems();if (thisMonth.equals((String) departureMonthJcb.getSelectedItem())) {for (int i = Integer.parseInt(thisDay); i <= monthDayNum[Integer.parseInt((thisMonth)) - 1]; i++) {departureDayJcb.addItem(String.valueOf(i));}} else {for (int i = 1; i <= monthDayNum[Integer.parseInt((String) (departureMonthJcb.getSelectedItem()))- 1]; i++) {departureDayJcb.addItem(String.valueOf(i));}}} else if (e.getSource() == buyJbt) {ticketkey = (String) departureJcb.getSelectedItem() + " " + (String) destinationJcb.getSelectedItem()+ " 2021." + (String) departureMonthJcb.getSelectedItem() + "."+ (String) departureDayJcb.getSelectedItem();// 判断有没有票if (!IOInfo.ticketInfo.containsKey(ticketkey))javax.swing.JOptionPane.showMessageDialog(null, "很抱歉,该线路并未开通航班");else {this.removeAll();this.add(welJlb);this.add(returnJbt);time = Integer.parseInt((String) personNumJcb.getSelectedItem());thisTime = 1;ticketChoice = new Hashtable<JRadioButton, JLabel>();int jrbY = 100, jrbX = 110;for (int j = 0; j < IOInfo.allTicketInfo.size(); j++) {String ticket = IOInfo.allTicketInfo.get(j);String[] strs = ticket.split("#");String[] price = strs[1].split(" ");if (strs[0].equals(ticketkey)) {jrb = new JRadioButton();jrb.setLocation(jrbX + 500, jrbY + 50);jrb.setSize(20, 20);jrb.addActionListener(this);JLabel jlb = new JLabel(strs[1]);jlb.setFont(new Font("楷体", Font.BOLD, 30));jlb.setSize(800, 40);jlb.setForeground(Color.red);jlb.setLocation(jrbX, jrbY);ticketChoice.put(jrb, jlb);JLabel jlb2 = new JLabel("头等舱:" + price[3] + "元" + "   " + "经济舱:" + price[4] + "元");jlb2.setFont(new Font("楷体", Font.BOLD, 30));jlb2.setSize(800, 40);jlb2.setForeground(Color.red);jlb2.setLocation(jrbX, jrbY + 50);jrbY += 100;this.add(jrb);this.add(jlb);this.add(jlb2);}}Enumeration<JRadioButton> tmpKeys = ticketChoice.keys();ButtonGroup bg = new ButtonGroup();while (tmpKeys.hasMoreElements()) {bg.add(tmpKeys.nextElement());}}} else {if (null != ticketChoice) {if (ticketChoice.containsKey(e.getSource())) {// tmp储存用户信息String tmp = null;while (null == tmp)tmp = javax.swing.JOptionPane.showInputDialog("请输入第" + String.valueOf(thisTime) + "位乘客的姓名、身份证号、舱位等级(空格隔开)");String[] strs = tmp.split(" ");String toBeAddAccountTicketInfo =  strs[0] + " " + strs[1] + " "+ (1 == Integer.parseInt(strs[2]) ? "头等舱" : "经济舱") + " " + ticketkey + " "+ ticketChoice.get(e.getSource()).getText();thisTime++;IOInfo.accountTicketInfo.add(toBeAddAccountTicketInfo);if (thisTime > time) {IOInfo.printInfo();javax.swing.JOptionPane.showMessageDialog(null, "恭喜您,预定成功");this.removeAll();Init();}}}}}
}

(4)

package Plane;import java.awt.*;
import java.awt.event.*;import javax.swing.*;public class FindPanel extends JPanel implements ActionListener {JLabel welJlb = new JLabel("机票查询");JButton returnJbt = new JButton("返回");JButton buyJbt = new JButton("确定");JLabel departureJlb = new JLabel("姓名");JLabel destinationJlb = new JLabel("身份证号");JLabel infoLabel = new JLabel(" 姓名 身份证号 舱位 始发地 目的地  日期    航空公司 航班号  时间");JTextField nameJtf = new JTextField();JTextField idNumJtf = new JTextField();public FindPanel() {Init();}void Init() {this.setSize(800, 600);this.setLayout(null);this.setVisible(true);this.add(welJlb);this.add(returnJbt);this.add(buyJbt);setLabel();welJlb.setFont(new Font("楷体", Font.BOLD, 40));welJlb.setSize(500, 100);welJlb.setLocation(320, 20);welJlb.setForeground(Color.yellow);returnJbt.addActionListener(this);returnJbt.setFont(new Font("楷体", Font.BOLD, 20));returnJbt.setSize(80, 25);returnJbt.setLocation(680, 520);returnJbt.setFocusable(false);buyJbt.addActionListener(this);buyJbt.setFont(new Font("楷体", Font.BOLD, 30));buyJbt.setSize(100, 40);buyJbt.setLocation(350, 420);buyJbt.setFocusable(false);this.add(nameJtf);nameJtf.setSize(200, 30);nameJtf.setFont(new Font("楷体", Font.BOLD, 30));nameJtf.setLocation(350, 210);this.add(idNumJtf);idNumJtf.setSize(200, 30);idNumJtf.setFont(new Font("楷体", Font.BOLD, 30));idNumJtf.setLocation(350, 310);}void setLabelContent(JLabel jlb, Font labelFont, int x, int y) {this.add(jlb);jlb.setForeground(Color.cyan);jlb.setFont(labelFont);jlb.setSize(200, 50);jlb.setLocation(x, y);}public void setLabel() {Font labelFont = new Font("楷体", Font.BOLD, 30);setLabelContent(departureJlb, labelFont, 220, 200);setLabelContent(destinationJlb, labelFont, 190, 300);}public void paintComponent(Graphics g) {Image img = new ImageIcon("graph//FindGraph.jpg").getImage();g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getSource() == buyJbt) {boolean flag = false;String toBeCmp = nameJtf.getText() + idNumJtf.getText();for (int i = 0; i < IOInfo.accountTicketInfo.size(); i++) {String info = IOInfo.accountTicketInfo.elementAt(i);String sorce = info.split(" ")[0] + info.split(" ")[1];if (sorce.equals(toBeCmp)) {flag = true;break;}}if (!flag) {javax.swing.JOptionPane.showMessageDialog(null, "对不起,查无此人!");idNumJtf.setText("");nameJtf.setText("");} else {this.removeAll();this.add(welJlb);this.add(returnJbt);int jrbX = 30, jrbY = 200;this.add(infoLabel);infoLabel.setFont(new Font("楷体", Font.BOLD, 20));infoLabel.setSize(800, 40);infoLabel.setForeground(Color.pink);infoLabel.setLocation(jrbX, jrbY - 60);for (int i = 0; i < IOInfo.accountTicketInfo.size(); i++) {String info = IOInfo.accountTicketInfo.elementAt(i);String sorce = info.split(" ")[0] + info.split(" ")[1];String[] strs = info.split(" ");info = "";for (int j = 0; j < 9; j++) {info += strs[j] + " ";}if (sorce.equals(toBeCmp)) {JLabel jlb = new JLabel(info);jlb.setFont(new Font("楷体", Font.BOLD, 20));jlb.setSize(800, 40);jlb.setForeground(Color.cyan);jlb.setLocation(jrbX, jrbY);this.add(jlb);jrbY += 50;}}}} else if (e.getSource() == returnJbt) {MainPanel.flag = Selection.mainPanel;idNumJtf.setText("");nameJtf.setText("");this.removeAll();Init();}}
}

(5)

package Plane;import java.awt.*;
import java.awt.event.*;
import java.util.*;import javax.swing.*;public class ChangePanel extends JPanel implements ActionListener {int time = 1;JLabel welJlb = new JLabel("退票改签");JButton returnJbt = new JButton("返回");JButton buyJbt = new JButton("确定");JLabel departureJlb = new JLabel("姓名");JLabel destinationJlb = new JLabel("身份证号");JLabel infoLabel = new JLabel(" 姓名 身份证号 舱位 始发地 目的地  日期    航空公司 航班号  时间");JTextField nameJtf = new JTextField();JTextField idNumJtf = new JTextField();Hashtable<JRadioButton, JLabel> ticketInfo = null;public ChangePanel() {Init();}void Init() {this.setSize(800, 600);this.setLayout(null);this.setVisible(true);this.add(welJlb);this.add(returnJbt);this.add(buyJbt);setLabel();welJlb.setFont(new Font("楷体", Font.BOLD, 40));welJlb.setSize(500, 100);welJlb.setLocation(320, 20);welJlb.setForeground(Color.yellow);returnJbt.addActionListener(this);returnJbt.setFont(new Font("楷体", Font.BOLD, 20));returnJbt.setSize(80, 25);returnJbt.setLocation(680, 520);returnJbt.setFocusable(false);buyJbt.addActionListener(this);buyJbt.setFont(new Font("楷体", Font.BOLD, 30));buyJbt.setSize(100, 40);buyJbt.setLocation(350, 420);buyJbt.setFocusable(false);this.add(nameJtf);nameJtf.setSize(200, 30);nameJtf.setFont(new Font("楷体", Font.BOLD, 30));nameJtf.setLocation(350, 210);this.add(idNumJtf);idNumJtf.setSize(200, 30);idNumJtf.setFont(new Font("楷体", Font.BOLD, 30));idNumJtf.setLocation(350, 310);}void setLabelContent(JLabel jlb, Font labelFont, int x, int y) {this.add(jlb);jlb.setForeground(Color.cyan);jlb.setFont(labelFont);jlb.setSize(200, 50);jlb.setLocation(x, y);}public void setLabel() {Font labelFont = new Font("楷体", Font.BOLD, 30);setLabelContent(departureJlb, labelFont, 220, 200);setLabelContent(destinationJlb, labelFont, 190, 300);}public void paintComponent(Graphics g) {Image img = new ImageIcon("graph//ChangeGraph.jpg").getImage();g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getSource() == buyJbt) {boolean flag = false;String toBeCmp = nameJtf.getText() + idNumJtf.getText();for (int i = 0; i < IOInfo.accountTicketInfo.size(); i++) {String info = IOInfo.accountTicketInfo.elementAt(i);String sorce = info.split(" ")[0] + info.split(" ")[1];if (sorce.equals(toBeCmp)) {flag = true;break;}}if (!flag) {javax.swing.JOptionPane.showMessageDialog(null, "对不起,查无此人!");idNumJtf.setText("");nameJtf.setText("");} else {this.removeAll();this.add(welJlb);this.add(returnJbt);int jrbX = 30, jrbY = 200;this.add(infoLabel);infoLabel.setFont(new Font("楷体", Font.BOLD, 20));infoLabel.setSize(800, 40);infoLabel.setForeground(Color.red);infoLabel.setLocation(jrbX, jrbY - 60);ticketInfo = new Hashtable<JRadioButton, JLabel>();for (int i = 0; i < IOInfo.accountTicketInfo.size(); i++) {String info = IOInfo.accountTicketInfo.elementAt(i);String sorce = info.split(" ")[0] + info.split(" ")[1];String[] strs = info.split(" ");if (sorce.equals(toBeCmp)) {JRadioButton jrb = new JRadioButton();this.add(jrb);jrb.setSize(20, 20);jrb.setLocation(jrbX - 23, jrbY + 10);JLabel jlb = new JLabel(info);jlb.setFont(new Font("楷体", Font.BOLD, 20));jlb.setSize(800, 40);jlb.setForeground(Color.cyan);jlb.setLocation(jrbX, jrbY);this.add(jlb);jrbY += 50;jrb.addActionListener(this);ticketInfo.put(jrb, jlb);}}ButtonGroup bg = new ButtonGroup();Enumeration<JRadioButton> keys = ticketInfo.keys();while (keys.hasMoreElements())bg.add(keys.nextElement());}} else if (e.getSource() == returnJbt) {MainPanel.flag = Selection.mainPanel;idNumJtf.setText("");nameJtf.setText("");this.removeAll();Init();} else {if (null != ticketInfo) {if (ticketInfo.containsKey(e.getSource())) {int choice = javax.swing.JOptionPane.showConfirmDialog(null, "您要改签还是退票", "改签选是,退票选否",JOptionPane.YES_NO_CANCEL_OPTION);if (choice == JOptionPane.NO_OPTION) {String toBeDelete = ticketInfo.get(e.getSource()).getText();IOInfo.accountTicketInfo.removeElement(toBeDelete);IOInfo.printInfo();javax.swing.JOptionPane.showMessageDialog(null, "退票成功!");this.removeAll();Init();} else if (choice == JOptionPane.YES_OPTION) {String toBeDelete = ticketInfo.get(e.getSource()).getText();IOInfo.accountTicketInfo.removeElement(toBeDelete);IOInfo.printInfo();this.removeAll();Init();MainPanel.flag = Selection.reServePanel;}}}}}
}

(6)

package Plane;import javax.swing.*;public class contentPanel extends JPanel implements Runnable {// 装载的其他面板static MainPanel mpl = new MainPanel();static ReservePanel rpl = new ReservePanel();static FindPanel fpl = new FindPanel();static ChangePanel cpl = new ChangePanel();contentPanel() throws Exception {this.setSize(mpl.getSize());this.setLayout(null);this.add(mpl);repaint();new Thread(this).start();}public void run() {while (true) {this.validate();repaint();if (MainPanel.flag != null) {this.removeAll();switch (MainPanel.flag) {case mainPanel:this.add(mpl);break;case reServePanel:this.add(rpl);break;case findPanel:this.add(fpl);break;case changePanel:this.add(cpl);break;}MainPanel.flag = null;}}}
}//枚举类型 方便确定当前选中的面板
enum Selection {mainPanel, reServePanel, findPanel, changePanel
}

(7)

package Plane;import javax.swing.*;
import java.awt.*;public class ClientFrame extends JFrame {Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();static contentPanel contentJpl = null;public ClientFrame() throws Exception {contentJpl = new contentPanel();this.setLocation((int) ((screenSize.getWidth() - 800) / 2), (int) ((screenSize.getHeight() - 600) / 3));Image img = Toolkit.getDefaultToolkit().getImage("graph//clientIcon.jpeg");this.setTitle("欢迎使用本系统");this.setSize(contentJpl.getSize());this.add(contentJpl);this.setVisible(true);this.setIconImage(img);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);}}

(8)

package Plane;import java.io.*;
import java.util.*;public class IOInfo {static PrintStream ps = null;static BufferedReader br = null;static final Hashtable<String, String> accountInfo = new Hashtable<String, String>();static final Hashtable<String, String> ticketInfo = new Hashtable<String, String>();static final Vector<String> allTicketInfo = new Vector<String>();static final Vector<String> accountTicketInfo = new Vector<String>();static Enumeration<String> keys = null;static Enumeration<String> ticketKeys = null;static {try {br = new BufferedReader(new FileReader("clientInfo\\AccountInfo.txt"));String tmp = null;String[] strs = null;while ((tmp = br.readLine()) != null) {strs = tmp.split("#");accountInfo.put(strs[0], strs[1]);}keys = accountInfo.keys();br.close();br = new BufferedReader(new FileReader("clientInfo\\TicketInfo.txt"));while ((tmp = br.readLine()) != null) {allTicketInfo.add(tmp);strs = tmp.split("#");ticketInfo.put(strs[0], strs[1] + strs[2]);}ticketKeys = ticketInfo.keys();br = new BufferedReader(new FileReader("clientInfo\\findTicket.txt"));while ((tmp = br.readLine()) != null) {accountTicketInfo.add(tmp);}br.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}static void printInfo() {try {ps = new PrintStream(new File("clientInfo\\AccountInfo.txt"));Enumeration<String> newkeys = accountInfo.keys();while (newkeys.hasMoreElements()) {String tmp = newkeys.nextElement();ps.println(tmp + "#" + accountInfo.get(tmp));}ps.close();ps = new PrintStream(new File("clientInfo\\TicketInfo.txt"));for(int i = 0 ; i < allTicketInfo.size();i++)ps.println(allTicketInfo.get(i));ps.close();ps = new PrintStream(new File("clientInfo\\findTicket.txt"));for(int i = 0 ; i < accountTicketInfo.size();i++)ps.println(accountTicketInfo.get(i));ps.close();} catch (Exception e) {e.printStackTrace();}}
}

4、课程设计总结
(1)收获
①可以运用多线程来判断是否切屏
因为程序在运行时要不停的判断当前应该显示的界面,所以判断函数需要放到死循环里,但是如果放到主进程里势必会阻塞进程,所以另开一个线程,用来判断当前应该显示的Panel
②repaint函数以及validate函数的应用
为了界面美观,我重载了paintComponen函数,但是发现在切屏后就无法重新绘制背景图片。后来经过查阅资料后明白,paintComponen函数会在系统认为需要绘制的时候调用,不过我们可以用repaint函数强制他重新绘制。但是这样又带来一个问题就是在一个死循环的进程中总是绘制会造成闪屏,影响使用体验,于是我在不需要切屏的时候把flag置为null,这样只有在切屏的时候才会重新绘制。此后还有一个问题是repaint函数会导致下拉菜单失去右边向下的那个小三角,经过查阅资料后发现,在repaint函数前调用validate函数即可解决。
③切屏的实现方法
最开始我想的方法是把所有的Panel都add到MainPanel上,然后调用不同Panel的setVisible函数来实现。但是这样带来的问题是不同Panel上的控件没有隐藏,当鼠标移动上去的时候就会出现。后来经过查阅资料发现,可以再增设一个Panel,用它来管理面板,切换的时候先removeAll,然后再add。
④进一步理解了java的进程
起初为了实现登陆后才能出现主界面,我设置了两个main函数,一个在RegisterFrame中,一个在ClientFrame中。同时在RegisterFrame中增设静态变量,在ClientFrame中读取静态变量的值,当他是true时就出现主界面,但是发现主界面永远不会出现。经过请教同学后明白,是因为在两个不同的进程中,同一个类会加载两次。虽然在RegisterFrame的main函数中修改了标记,但是ClientFrame进程读取的位置是另一个标记点,所以主界面永远无法出现。后来减少了一个main函数,把处理逻辑全部放到RegisterFrame中解决了这个问题。
⑤集合的选取
因为可能有多个用户同时操作,那么可能会出现同时访问集合的情况,所以我选择了Vector和Hashtable,以此来保证线程安全。
(2)不足
①登陆界面没有提供注册功能
②查询机票时没有设置自动过滤掉已起飞航班的功能
③购买多张机票时默认多个用户购买同一张机票
④查询功能过于粗暴,输入身份证和姓名就可以查询,忽略了对隐私的保护,应修改为只能查询通过自己账号购买的机票
⑤改签功能的实现是先退票,再让用户重新购买,与现实差别过大
⑥用户信息直接储存在文本文档中,没有进行加密处理

Java实现航空机票订票系统相关推荐

  1. 基于java的航空机票订票系统的开发——计算机毕业设计

    本系统在设计方面采用B/S模式,同时使用JSP技术进行基本页面的设计与功能实现,后台数据库选用MYSQL数据库.本系统可以实现用户查询航线时各个类别列表显示.机票的订阅和预订情况的直观查看.同时管理员 ...

  2. (附源码)ssm航空客运订票系统 毕业设计 141612

    SSM航空客运订票系统 摘 要 信息化社会内需要与之针对性的信息获取途径,但是途径的扩展基本上为人们所努力的方向,由于站在的角度存在偏差,人们经常能够获得不同类型信息,这也是技术最为难以攻克的课题.针 ...

  3. ssm航空客运订票系统 毕业设计源码141612

    SSM航空客运订票系统 摘 要 信息化社会内需要与之针对性的信息获取途径,但是途径的扩展基本上为人们所努力的方向,由于站在的角度存在偏差,人们经常能够获得不同类型信息,这也是技术最为难以攻克的课题.针 ...

  4. C++数据结构 航空客运订票系统

    航空客运订票系统  问题描述:业务主要包括查询航线和客票预订的信息.客票预订和办理 退票等.  基本要求: 系统必须能存储以下数据信息: 航班信息:飞机抵达城市.航班号.飞机号.起降时间.票价.总 ...

  5. 【数据结构应用】航空客运订票系统

    目录 前言 一.作业要求介绍 二.各个函数的实现 1.头文件总结需要的功能 (1)结构体的定义 (2)各个功能的函数 2.各个函数的具体实现 (1)初始化 (2)打印航班信息表 (4)查找航班信息 ( ...

  6. C语言版-数据结构-期末课程设计-大作业(航空客运订票系统)附源码+实验文档

    设计题目:航空客运订票系统 本项目涉及到的知识:指针.结构体数组.链表.参数传递 [问题描述]航空客运订票的业务活动包含查询航线和客票预订信息,可以办理订.退票等,用c语言设计一个程序模拟实现. 一. ...

  7. 基于Java+Swing+mysql飞机票订票系统

    基于Java+Swing+mysql飞机票订票系统 一.系统介绍 二.功能展示 1.用户登陆 2.注册 3.综合查询(管理员) 4.航班录入(管理员) 4.查询航班 5.机票预定 6.机票退改管理 三 ...

  8. C++课程设计:航空客运订票系统

    航空客运订票系统 选题背景 方案论证 过程论述 运行结果 完整代码 选题背景 ①背景: 现在人们更多的使用飞机作为出行交通工具,因此机票票务市场也在快速发展.国内外航空事业在飞速发展,各航空公司对票务 ...

  9. 航空客运订票系统(C语言,软件用的DEV)

    这两天整理之前的作业代码,把自己一点一点敲出来的系统又看了一下,挑几个发出来供大家参考.想要源码.报告可以找我啦,代码的注释之前写的都是非常详细的! 但是不是无偿的啦(不坑,一杯奶茶喽,不做白嫖怪啦^ ...

最新文章

  1. python安装教程3.8.5-怎么安装最新Python3.8.5-新手入门教程必看
  2. “男儿有泪不轻弹”和“活着”
  3. 站长们都会,但是都会写错的robots!
  4. Python之面向对象继承和派生
  5. php header运用细节
  6. 客座编辑:杜小勇(1963-),男,中国人民大学信息学院教授,博士生导师,教育部数据工程与知识工程重点实验室主任。...
  7. 2场直播丨从零快速搭建一整套监控体系、Oracle Database Server经典体系结构
  8. TeXmacs - 所见即所得 - 专业排版软件
  9. mongodb用户管理和服务安装
  10. oVirt guest | VM HOST HA in one Cluster
  11. 云创大数据荣获“南京实体经济十大优秀企业”
  12. 中文文本分析工具总结
  13. 新装的电脑没有打开图片的软件怎么办?教你打开Windows照片查看器
  14. 基本遗传算法(GA)的算法原理、步骤、及Matlab实现
  15. 小蚁智能摄像机无法连接服务器,小米摄像头连接不上
  16. 推荐一款办公室必备股票看盘工具
  17. H.264再学习 -- 详解 H.264 NALU语法结构
  18. 关于长高问题 我的看法
  19. D妹上新|DoH和DoT开始公测啦!
  20. 电影: 嘲笑过片名后,我哭着看完这部片

热门文章

  1. 一键修复手机电池_怎么恢复手机电池寿命(教你一键修复电池损耗)
  2. ValueError:Traceback(most ...)数据集中图片 not exists
  3. vue工程,高德地图信息窗体模块化插入,及信息窗口点击事件
  4. web前端代码开发工具_Web开发人员的有用代码比较工具
  5. 10和100Mbps以太网
  6. 双11到了,月薪5千的人如何赚到2万?这里有5个技巧!
  7. 服务器老被攻击?如何避免服务器被恶意攻击?
  8. js:两种方法实现键盘按键控制
  9. r语言绘制精美pcoa图_[R语言 学习笔记]用R做主坐标分析(PCoA)
  10. rx6600怎么样 rx6600显卡相当于什么n卡