📄 flightsystem.java
字号:
courseOK.setEnabled(true);
CLIENT.setEnabled(true);
VIPCLIENT.setEnabled(true);
NEW_CLIENT.setEnabled(true);
}
}
/**
* the refuelListener implements ActionListener
* @author name
*
*/
class refuelListener implements ActionListener {
/**
* @param the refuelListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
frame_VIP.dispose();
frame_VIP_refuel.setSize(300, 140);
frame_VIP_refuel.setTitle("VIP refuel!");
frame_VIP_refuel.setLocation(460,220);
frame_VIP_refuel.setContentPane(refuel.getPanel());
frame_VIP_refuel.setVisible(true);
}
}
/**
* the login_OKListener implements ActionListener
* @author name
*
*/
class login_OKListener implements ActionListener {
/**
* @param the login_OKListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
for(Iterator iterator = clientdb.getIterator(); iterator.hasNext();){
Object temp = iterator.next();
if(temp instanceof VIPClient && clientformatter==VIPClientFormatter.getSingletonInstance()) {
Vipclient = (VIPClient)temp;
if(ID.getText().equals(Vipclient.getID()) && password.getText().equals(Vipclient.getPWD())) {
client = (Client)temp;
logout.setEnabled(true);
flightLogin.setEnabled(false);
frame_VIP_Login.dispose();
frame_VIP.setSize(440, 500);
frame_VIP.setTitle("VIP BOOK");
frame_VIP.setLocation(460,320);
frame_VIP.setVisible(true);
frame_VIP.setContentPane(window.getPanel());
frame_VIP.setDefaultCloseOperation(0);
left.setText(new Integer(Vipclient.getLeftLength()).toString());
code = (String)flightList.getSelectedValue();
StringTokenizer stk = new StringTokenizer(code, "_");
FlightItem flight = new FlightItem();
flight = query.getItem(stk.nextToken());
if(Vipclient.getLeftLength() - flight.getLength()>=0){
buyleft.setText(new Integer(Vipclient.getLeftLength() - flight.getLength()).toString());
}
else buyleft.setText("Your Length is not enough!");
vname.setText(Vipclient.getName());
vid.setText(Vipclient.getID());
vadd.setText(Vipclient.getAddress());
ticketcode = flightItem.getFlightCode() + Vipclient.getID() + (int)(Math.random() * 999 + 1);
frame_VIP_Login = null;
return;
}
} else if(clientformatter==CustomerFormatter.getSingletonInstance()){
client = (Client)temp;
if(ID.getText().equals(client.getID()) && password.getText().equals(client.getPWD())) {
logout.setEnabled(true);
flightLogin.setEnabled(false);
frame_VIP_Login.dispose();
frame_client.setSize(300, 300);
frame_client.setTitle("Client Book");
frame_client.setLocation(460, 320);
frame_client.setContentPane(cwindow.getPanel());
frame_client.setDefaultCloseOperation(0);
frame_client.setVisible(true);
cname.setText(client.getName());
cid.setText(client.getID());
cadd.setText(client.getAddress());
ticketcode = flightItem.getFlightCode() + client.getID() + (int)(Math.random() * 999 + 1);
frame_VIP_Login = null;
return;
}
}
}
JOptionPane.showMessageDialog(null, "Sorry,invalid input!Please try again!");
password.setText(null);
Point location = new Point(400, 260);
frame_VIP_Login.setLocation(location);
frame_VIP_Login.setTitle("VIP Login");
login = new VIP_Login();
frame_VIP_Login.setContentPane(login.getPanel());
frame_VIP_Login.setVisible(true);
}
}
/**
* the VIP_buyListener implements ActionListener
* @author name
*
*/
class VIP_buyListener implements ActionListener {
/**
* @param the VIP_buyListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
try {
if(Integer.parseInt(buyleft.getText()) < 0) {
JOptionPane.showMessageDialog(null, "Sorry, your account is not enough!",
"Information", JOptionPane.CANCEL_OPTION);
return;
}
} catch (NumberFormatException nfe) {
// TODO: handle exception
JOptionPane.showMessageDialog(null, "Sorry, your account is not enough!",
"Information", JOptionPane.CANCEL_OPTION);
frame_VIP.dispose();
flightLogin.setEnabled(false);
flightOK.setEnabled(false);
BookOK.setEnabled(false);
Reserve.setEnabled(false);
courseOK.setEnabled(true);
newCliReg.setEnabled(false);
VIPCLIENT.setEnabled(true);
CLIENT.setEnabled(true);
NEW_CLIENT.setEnabled(true);
statusTextArea.setText(null);
query.removeAllQuery();
flightList.setListData(query.getQuery());
return;
}
if (JOptionPane.showConfirmDialog(null, "confirm???",
"Information", JOptionPane.YES_NO_OPTION)== JOptionPane.YES_OPTION) {
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"
+ "Condition: VIP_Seat Sell Out!");
VIPClient VIP_client = (VIPClient)client;
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();
}
VIP_client.setReserved(false);
VIP_client.setTicke(new Tickit(ticketcode,classtype,cabinprice,flightItem));
VIP_client.setFlightItem(flightItem);
left.setText(buyleft.getText());
if (flag == -1) {
JOptionPane.showMessageDialog(null, "the ticket will be sent to you within 3 days!", "warning",JOptionPane.OK_OPTION );
}
else{
JOptionPane.showMessageDialog(null, "your ticket code is "+ticketcode+"!", "Keep It!!",JOptionPane.OK_OPTION );
}
try {
Vipclient.setLeftLength(Integer.parseInt(left.getText()));
buyleft.setText("You have bought this ticket.");
statusTextArea.setText("You have bought this ticket.\nThank you for your choosing our company!");
flightOK.setEnabled(false);
BookOK.setEnabled(false);
Reserve.setEnabled(false);
frame_VIP.dispose();
} catch (NumberFormatException nfe) {
// TODO: handle exception
JOptionPane.showMessageDialog(null, "Sorry, your account is not enough!",
"Information", JOptionPane.CANCEL_OPTION);
}
}
}
}
/**
* the Client_buyListener implements ActionListener
* @author name
*
*/
class Client_buyListener implements ActionListener {
/**
* @param the Client_buyListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
if (JOptionPane.showConfirmDialog(null, "confirm???",
"Information", JOptionPane.YES_NO_OPTION)== JOptionPane.YES_OPTION) {
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"
+ "Condition: VIP_Seat Sell Out!");
left.setText(buyleft.getText());
//Vipclient.setLeftLength(new Integer(left.getText()));
buyleft.setText("You have bought this ticket.");
statusTextArea.setText("You have bought this ticket.\nThank you for your choosing our company!");
flightOK.setEnabled(false);
BookOK.setEnabled(false);
Reserve.setEnabled(false);
frame_client.dispose();
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.setReserved(false);
client.setTicke(new Tickit(ticketcode,classtype,cabinprice,flightItem));
client.setFlightItem(flightItem);
if (flag == -1) {
JOptionPane.showMessageDialog(null, "the ticket will be sent to you within 3 days!", "warning",JOptionPane.OK_OPTION );
}
else{
JOptionPane.showMessageDialog(null, "your ticket code is "+ticketcode+"!", "Keep It!!",JOptionPane.OK_OPTION );
}
}
}
}
/**
* the VIPReserveListener implements ActionListener
* @author name
*
*/
class VIPReserveListener implements ActionListener {
/**
* @param the VIPReserveListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
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"
+ "Reserve: Seat_Reserve");
}
}
/**
* the exitRefuelListener implements ActionListener
* @author name
*
*/
class exitRefuelListener implements ActionListener {
/**
* @param the exitRefuelListener of exitListener
*/
public void actionPerformed(ActionEvent event) {
frame_VIP_refuel.dispose();
frame_VIP.setVisible(true);
}
}
/**
* the VIP_Window extends JPanel
* @author name
*
*/
public class VIP_Window extends JPanel {
/* Window Window in VIP_Window */
private JPanel Window = new JPanel(new GridLayout(0, 1));
/* Window pnlradioButton in VIP_Window */
private JPanel pnlradioButton;
/* Window Left in VIP_Window */
private JLabel Left;
/* Window Buyleft in VIP_Window */
private JLabel Buyleft;
/* Window vipname in VIP_Window */
private JLabel vipname;
/* Window vipid in VIP_Window */
private JLabel vipid;
/* Window vipadd in VIP_Window */
private JLabel vipadd;
/* Window refuel in VIP_Window */
private JButton refuel;
/* Window exit in VIP_Window */
private JButton exit;
/* Window buy in VIP_Window */
private JButton buy;
/* Window VIPReserve in VIP_Window */
private JButton VIPReserve;
/**
* the constructor of VIP_Window
*
*/
VIP_Window() {
P_ticket = new JRadioButton("Paper ticket",true);
E_ticket = new JRadioButton("Electronic ticket");
tickets = new ButtonGroup();
Left = new JLabel("your obligate length:",JLabel.CENTER);
Buyleft = new JLabel("obligate length after buy:",JLabel.CENTER);
left = new JTextField();
vipname = new JLabel("Your Name",JLabel.CENTER);
vipid = new JLabel("Your ID",JLabel.CENTER);
vipadd = new JLabel("Your Address:",JLabel.CENTER);
pnlradioButton = new JPanel(new FlowLayout());
tickets.add(P_ticket);
tickets.add(E_ticket);
pnlradioButton.add(P_ticket);
pnlradioButton.add(E_ticket);
vname = new JTextField();
vid = new JTextField();
vadd = new JTextField();
buyleft = new JTextField();
left.setEditable(false);
buyleft.setEditable(false);
refuel = new JButton("Charge");
VIPReserve = new JButton("Reserve");
exit = new JButton("Exit");
buy = new JButton("Buy");
vname.setEditable(false);
vid.setEditable(false);
vadd.setEditable(false);
JPanel account = new JPanel(new GridLayout(0,2));
JPanel now = new JPanel(new GridLayout(0,2));
JPanel VIP_btn = new JPanel(new FlowLayout());
JPanel vip_name = new JPanel(new GridLayout(0,2));
JPanel vip_id = new JPanel(new GridLayout(0,2));
JPanel vip_add = new JPanel(new GridLayout(0,2));
vip_name.add(vipname);
vip_name.add(vname);
vip_id.add(vipid);
vip_id.add(vid);
vip_add.add(vipadd);
vip_add.add(vadd);
account.add(Left);
account.add(left);
now.add(Buyleft);
now.add(buyleft);
VIP_btn.add(buy);
VIP_btn.add(VIPReserve);
VIP_btn.add(refuel);
VIP_btn.add(exit);
Window.add(vip_name);
Window.add(vip_id);
Window.add(vip_add);
Window.add(account);
Window.add(now);
Window.add(pnlradioButton);
Window.add(VIP_btn);
Window.setSize(350,420);
refuel.addActionListener(new refuelListener());
exit.addActionListener(new exitListener());
buy.addActionListener(new VIP_buyListener());
VIPReserve.addActionListener(new ReserveListener());
flag = -1;
class radiobuttonlistener implements ActionListener{
public void actionPerformed(ActionEvent a){
flag *= -1;
}
}
P_ticket.addActionListener(new radiobuttonlistener());
E_ticket.addActionListener(new radiobuttonlistener());
}
/**
* the meath of getPanel
* @return Window
*/
public JPanel getPanel() {
return Window;
}
}
/**
* the refuel_OKListener implements ActionListener
* @author name
*
*/
class refuel_OKListener implements ActionListener {
/**
* @param the refuel_OKListener of exitListener
*/
public void actionPerformed(ActionEvent event){
try {
if (Integer.parseInt(amount.getText()) <= 0) {
JOptionPane.showMessageDialog(null, "Sorry,invalid input!");
return;
}
} catch (NumberFormatException e) {
// TODO: handle exception
JOptionPane.showMessageDialog(null, "Sorry,invalid input!");
return;
}
Vipclient.setLeftLength(Vipclient.getLeftLength() + Integer.parseInt(amount.getText()));
JOptionPane.showMessageDialog(null, "Charge completerd!");
frame_VIP_refuel.dispose();
left.setText(new Integer(Vipclient.getLeftLength()).toString());
buyleft.setText(new Integer(Vipclient.getLeftLength() - flightItem.getLength()).toString());
frame_VIP.setVisible(true);
}
}
/**
* the Client_Window extends JPanel
* @author name
*
*/
public class Client_Window extends JPanel {
/* Window Window in Client_Window */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -