📄 flightsystem.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
/**
* Gourmet Coffee System.
*
* @author author name
* @version 1.1.0
* @see Product
* @see Coffee
* @see CoffeeBrewer
* @see Catalog
* @see OrderItem
* @see Order
* @see Sales
* @see CatalogLoader
* @see FileCatalogLoader
* @see DataFormatException
* @see SalesFormatter
* @see PlainTextSalesFormatter
* @see HTMLSalesFormatter
* @see XMLSalesFormatter
*/
public class FlightSystem extends JPanel {
/* Stander error stream */
static private PrintWriter stdErr = new PrintWriter(System.err, true);
/* Window width in pixels */
static private int WIDTH = 1020;
/* Window height in pixels */
static private int HEIGHT = 645;
/* Window x in pixels */
static private int x;
/* Window y in pixels */
static private int y;
/* Window point in pixels */
static private final Point point = new Point(x = 230, y = 60);
/* Window frame in pixels */
static private JFrame frame;
/* Window frame_client in pixels */
static private JFrame frame_client = new JFrame();
/* Window frame_VIP_Login in pixels */
static private JFrame frame_VIP_Login ;
/* Window frame_newClient in pixels */
static private JFrame frame_newClient = new JFrame();
/* Window frame_VIP in pixels */
static private JFrame frame_VIP = new JFrame();
/* Window frame_VIP_refuel in pixels */
static private JFrame frame_VIP_refuel = new JFrame();
/* Window frame_reserved in pixels */
static private JFrame frame_reserved ;
/* Window login_reserved in pixels */
private JFrame login_reserved ;
/* Window Vipclient in pixels */
private VIPClient Vipclient = new VIPClient();
/* Window client in pixels */
private Client client = new Client();
/* Window flightItem in pixels */
private FlightItem flightItem = new FlightItem();
/* Window code in pixels */
private String code;
/* Window ticketcode in pixels */
private String ticketcode;
/* Window statusTextArea in pixels */
private JTextArea statusTextArea;
/* Window ticketsTextArea in pixels */
private JTextArea ticketsTextArea;
/* Window amount in pixels */
private JTextField amount;
/* Window left in pixels */
private JTextField left;
/* Window buyleft in pixels */
private JTextField buyleft;
/* Window LeavePlace in pixels */
private JLabel LeavePlace;
/* Window Destination in pixels */
private JLabel Destination;
/* Window CabinType in pixels */
private JLabel CabinType;
/* Window welcome in pixels */
private JLabel welcome;
/* Window leavePlace in pixels */
private JComboBox leavePlace;
/* Window destination in pixels */
private JComboBox destination;
/* Window cabinType in pixels */
private JComboBox cabinType;
/* Window login in pixels */
private VIP_Login login;
/* Window window in pixels */
private VIP_Window window = new VIP_Window();
/* Window refuel in pixels */
private VIP_Refuel refuel = new VIP_Refuel();
/* Window cwindow in pixels */
private Client_Window cwindow = new Client_Window();
/* Window reserved_window in pixels */
private Reserved_Window reserved_window ;
/* Window E_ticket in pixels */
private JRadioButton E_ticket;
/* Window P_ticket in pixels */
private JRadioButton P_ticket;
/* Window tickets in pixels */
private ButtonGroup tickets;
/* Window vname in pixels */
private JTextField vname;
/* Window vid in pixels */
private JTextField vid;
/* Window vadd in pixels */
private JTextField vadd;
/* Window cname in pixels */
private JTextField cname;
/* Window cid in pixels */
private JTextField cid;
/* Window cadd in pixels */
private JTextField cadd;
/* Window ID in pixels */
private JTextField ID;
/* Window password in pixels */
private JPasswordField password;
/* Window flightList in pixels */
private JList flightList;
/* Window CLIENT in pixels */
private JRadioButton CLIENT;
/* Window VIPCLIENT in pixels */
private JRadioButton VIPCLIENT;
/* Window NEW_CLIENT in pixels */
private JRadioButton NEW_CLIENT;
/* Window flightLogin in pixels */
private JButton flightLogin;
/* Window courseOK in pixels */
private JButton courseOK;
/* Window newCliReg in pixels */
private JButton newCliReg;
/* Window BookOK in pixels */
private JButton BookOK;
/* Window flightOK in pixels */
private JButton flightOK;
/* Window Reserve in pixels */
private JButton Reserve;
/* Window Reset in pixels */
private JButton Reset;
/* Window logout in pixels */
private JButton logout;
/* Window getReserved in pixels */
private JButton getReserved;
/* Window classtype in pixels */
private String classtype;
/* Window flag in pixels */
private int flag ;
/* Window clientformatter in pixels */
private ClientFormatter clientformatter=NEW_ClientFormatter.getSingletonInstance();
/* Window flightdb in pixels */
private FlightDB flightdb;
/* Window clientdb in pixels */
private ClientDB clientdb;
/* Window query in pixels */
private PreQuery query = new PreQuery();
/* Window fileChooser in pixels */
private MyFileChooser fileChooser;
/**
* Loads a product catalog and starts the application.
*
* @param args String arguments. Not used.
* @throws IOException if there are errors in the loading the catalog.
*/
public static void main(String[] args) throws IOException {
String filename1 = "";
String filename2 = "";
if (args.length != 2) {
filename1 = "d:/FlightDB.txt";
filename2 = "d:/Client.txt";
} else {
filename1 = args[0];
filename2 = args[1];
}
try {
FlightDB flightdb = (new FileCatalogLoader()).loadFlightDB(filename1);
ClientDB clientdb = (new FileCatalogLoader()).loadClientDB(filename2);
frame = new JFrame("Blue Skies");
frame.setContentPane(new FlightSystem(flightdb, clientdb));
frame.setDefaultCloseOperation(0);
frame.setLocation(point);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(true);
frame.setVisible(true);
} catch (FileNotFoundException fnfe) {
stdErr.println("The file does not exist");
System.exit(1);
} catch (DataFormatException dfe) {
stdErr.println("The file contains malformed data: "
+ dfe.getMessage());
System.exit(1);
}
}
/**
* Instantiates the components and arranges them in a window.
*
* @param initialCatalog a product catalog.
*/
public FlightSystem(FlightDB initialFlightDB, ClientDB initialClientDB) {
// create the components
String[] start = {"Denver", "Washington D.C.", "Los Angeles","New York", "Cleveland", "Wikipedia","Atlanta"};
String[] end = {"Denver", "Washington D.C.", "Los Angeles", "New York", "Cleveland", "Wikipedia","Atlanta"};
String[] cabin = {"First Class", "Business Class", "Economy Class"};
welcome = new JLabel("Welcome to Blue Skies!");
LeavePlace = new JLabel("Please select the LeavePlace");
LeavePlace.setHorizontalAlignment(JLabel.CENTER);
Destination = new JLabel("Please select the Destination");
Destination.setHorizontalAlignment(JLabel.CENTER);
CabinType = new JLabel("Please select the Cabin");
CabinType.setHorizontalAlignment(JLabel.CENTER);
leavePlace = new JComboBox(start);
destination = new JComboBox(end);
cabinType = new JComboBox(cabin);
flightLogin = new JButton("Login");
courseOK = new JButton("OK");
newCliReg = new JButton("Register");
BookOK = new JButton("OK");
flightOK = new JButton("OK");
Reserve = new JButton("Reserve");
Reset = new JButton("Reset");
logout = new JButton("Logout");
getReserved = new JButton("getReserved");
flightLogin.setEnabled(false);
flightOK.setEnabled(false);
BookOK.setEnabled(false);
Reserve.setEnabled(false);
newCliReg.setEnabled(false);
logout.setEnabled(false);
Reset.setEnabled(false);
setLayout(new BorderLayout());
JPanel welcomeInfo = new JPanel();
welcomeInfo.setBorder(
BorderFactory.createTitledBorder("Blue Skies"));
welcomeInfo.add(welcome);
JPanel flightInforPanel = new JPanel(new GridLayout(2, 1));
JPanel flightInfo = new JPanel();
JPanel flight_buttons = new JPanel();
flightInforPanel.setBorder(
BorderFactory.createTitledBorder("Flight Information"));
flightList = new JList();
flightList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
flight_buttons.add(flightOK);
flightInfo.add(new JScrollPane(flightList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
flightInforPanel.add(flightInfo, BorderLayout.NORTH);
flightInforPanel.add(flight_buttons, BorderLayout.SOUTH);
flightInforPanel.setSize(100, 150);
JPanel ticketInforPanel = new JPanel(new GridLayout(2, 1));
JPanel ticketInformation = new JPanel();
JPanel ticketButtonPanel = new JPanel();
ticketInforPanel.setBorder(
BorderFactory.createTitledBorder("Ticket Information"));
ticketsTextArea = new JTextArea(40, 25);
ticketsTextArea.setEditable(false);
ticketsTextArea.getBounds();
ticketInformation.add(new JScrollPane(ticketsTextArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
ticketButtonPanel.add(flightLogin, BorderLayout.WEST);
ticketButtonPanel.add(newCliReg);
ticketButtonPanel.add(logout);
ticketButtonPanel.add(getReserved);
newCliReg.addActionListener(new RegisterListener());
ticketInforPanel.add(ticketInformation, BorderLayout.NORTH);
ticketInforPanel.add(ticketButtonPanel, BorderLayout.SOUTH);
JPanel courseChoicePanel = new JPanel(new GridLayout(20, 2));
JPanel courseTop = new JPanel(new GridLayout(1, 2));
JPanel courseCenter = new JPanel(new GridLayout(1, 2));
JPanel courseBottom = new JPanel(new FlowLayout());
JPanel flight_cabin = new JPanel(new GridLayout(1, 2));
JPanel radioButtons = new JPanel(new GridLayout(1, 3));
NEW_CLIENT = new JRadioButton("NEW_CLIENT", true);
CLIENT = new JRadioButton("CLIENT");
VIPCLIENT = new JRadioButton("VIPCLIENT");
tickets.add(P_ticket);
tickets.add(E_ticket);
ButtonGroup group = new ButtonGroup();
group.add(NEW_CLIENT);
group.add(CLIENT);
group.add(VIPCLIENT);
courseChoicePanel.setBorder(
BorderFactory.createTitledBorder("Course"));
courseTop.add(LeavePlace);
courseTop.add(leavePlace);
courseCenter.add(Destination);
courseCenter.add(destination);
flight_cabin.add(CabinType);
flight_cabin.add(cabinType);
courseBottom.add(courseOK);
courseBottom.add(Reset);
//courseBottm.add(logout);
radioButtons.add(NEW_CLIENT);
radioButtons.add(CLIENT);
radioButtons.add(VIPCLIENT);
courseChoicePanel.setLayout(new GridLayout(7, 2));;
courseChoicePanel.add(courseTop);
courseChoicePanel.add(courseCenter);
courseChoicePanel.add(flight_cabin);
courseChoicePanel.add(radioButtons);
courseChoicePanel.add(courseBottom);
JPanel statusTextPanel = new JPanel();
statusTextPanel.setBorder(
BorderFactory.createTitledBorder("Information"));
statusTextArea = new JTextArea(8, 65);
statusTextArea.setEditable(false);
statusTextPanel.add(statusTextArea);
JPanel exitPanel = new JPanel();
JPanel empty1 = new JPanel();
JPanel empty2 = new JPanel();
exitPanel.setBorder(
BorderFactory.createTitledBorder("Exit"));
JButton exitButton = new JButton("Exit");
exitPanel.setLayout(new GridLayout(6, 3));
exitPanel.add(empty1, BorderLayout.NORTH);
exitPanel.add(empty2, BorderLayout.CENTER);
exitPanel.add(exitButton, BorderLayout.SOUTH);
JPanel topPanel = new JPanel(new BorderLayout());
JPanel centralPanel = new JPanel(new BorderLayout());
JPanel bottomPanel = new JPanel(new BorderLayout());
topPanel.add(welcomeInfo);
centralPanel.add(courseChoicePanel, BorderLayout.WEST);
centralPanel.add(flightInforPanel, BorderLayout.CENTER);
centralPanel.add(ticketInforPanel, BorderLayout.EAST);
bottomPanel.add(statusTextPanel, BorderLayout.WEST);
bottomPanel.add(exitPanel, BorderLayout.CENTER);
setLayout(new BorderLayout());
add(topPanel, BorderLayout.NORTH);
add(centralPanel, BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
flightdb = initialFlightDB;
clientdb = initialClientDB;
flightOK.addActionListener(new flightOKListener());
courseOK.addActionListener(new courseOKListener());
BookOK.addActionListener(new BookOKListener());
exitButton.addActionListener(new ExitButtonListener());
VIPCLIENT.addActionListener(new VIPClientListener());
NEW_CLIENT.addActionListener(new New_ClientListener());
CLIENT.addActionListener(new ClientListener());
Reserve.addActionListener(new ReserveListener());
flightLogin.addActionListener(new flightLoginListener());
Reset.addActionListener(new resetListener());
logout.addActionListener(new resetListener());
getReserved.addActionListener(new GetReservedListener());
}
/**
* the ReserveListener implements ActionListener
* @author name
*
*/
class ReserveListener implements ActionListener {
/**
* @param the actionpermed of ReserveListener
*/
public void actionPerformed(ActionEvent event) {
String ticketcode = flightItem.getFlightCode() + client.getID();
ticketsTextArea.setText("FlightCode: " + flightItem.getFlightCode() + "\n"
+ "Date: " + flightItem.getDate() + "\n"
+ "Start: " + flightItem.getLeftPlace() + "\n"
+ "Destination: " + flightItem.getArrPlace() + "\n"
+ "CabinType: " + classtype + "\n"
+ "Price: " + flightItem.getCabin().getPriceOfFC() + "\n"
+ "Length: " + flightItem.getLength() + "\n"
+ "TicketCode: " + ticketcode + "\n"
+ "Reserved: Yes");
statusTextArea.setText("You have reserved this ticket.");
double cabinprice;
if (classtype.equals("First Class")) {
cabinprice= flightItem.getCabin().getPriceOfFC();
}else if (classtype.equals("Business Class")) {
cabinprice= flightItem.getCabin().getPriceOfBC();
}
else{
cabinprice= flightItem.getCabin().getPriceOfEC();
}
client.setTicke(new Tickit(ticketcode,classtype,cabinprice,flightItem));
client.setReserved(true);
}
}
/**
* the RegisterListener implements ActionListener
* @author name
*
*/
class RegisterListener implements ActionListener{
/**
* @param the actionpermed of RegisterListener
*/
public void actionPerformed(ActionEvent event){
final JFrame f=new JFrame();
final JRadioButton R_Client =new JRadioButton("Client");
final JRadioButton R_VIPClient =new JRadioButton("VIPClient");
final JLabel L_name=new JLabel("Name");
final JTextField T_name=new JTextField();
final JLabel L_ID=new JLabel("ID");
final JTextField T_ID=new JTextField();
final JLabel L_PWD=new JLabel("PassWord");
final JTextField T_PWD=new JTextField();
final JLabel L_Address=new JLabel("Address");
final JTextField T_Address=new JTextField();
final JButton Reg_OK =new JButton("OK");
final JButton Reg_EXIT =new JButton("EXIT");
final ClientFormatter client_formatter=CustomerFormatter.getSingletonInstance();
JPanel Reg_radioButtons = new JPanel(new GridLayout(1, 2));
ButtonGroup Reg_group = new ButtonGroup();
Reg_group.add(R_Client);
Reg_group.add(R_VIPClient);
Reg_radioButtons.add(R_Client);
Reg_radioButtons.add(R_VIPClient);
f.setLayout(new GridLayout(6,2));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -