⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flightsystem.java

📁 java的一个gui工程示例
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			f.setSize(400,180);
			f.setLocation(500, 300);
			
			R_Client.addActionListener(new ClientListener());
			R_VIPClient.addActionListener(new VIPClientListener());
			
			f.add(R_Client);
			f.add(R_VIPClient);
			
			f.add(L_name);
			f.add(T_name);
			f.add(L_ID);
			f.add(T_ID);
			f.add(L_PWD);
			f.add(T_PWD);
			f.add(L_Address);
			f.add(T_Address);
			f.add(Reg_OK);
			f.add(Reg_EXIT);
			f.setVisible(true);
			
			
			
			/**
			 * the Reg_OK_Listener implements ActionListener
			 * @author name
			 *
			 */
			class Reg_OK_Listener implements ActionListener{
				
				/**
				 * @param the actionpermed of Reg_OK_Listener
				 */
				public void actionPerformed(ActionEvent event){
					if(clientformatter==CustomerFormatter.getSingletonInstance()){
						
						Client client=new Client(T_name.getText(),T_ID.getText(),T_PWD.getText(),T_Address.getText());
						clientdb.addClientItem(client);
						//statusTextArea.setText("You hasasasasass ticket.");
						CLIENT.setEnabled(true);
						flightLogin.setEnabled(true);
						newCliReg.setEnabled(false);
						
						
					}
					
					else{
						VIPClient vip=new VIPClient(T_name.getText(),T_ID.getText(),T_PWD.getText(),T_Address.getText());
						clientdb.addClientItem(vip);
						VIPCLIENT.setEnabled(true);
						flightLogin.setEnabled(true);
						newCliReg.setEnabled(false);
					}
					statusTextArea.setText("You have registed it !\n Please Login!");
				}
			}
			/**
			 * the Reg_ExitLisener implements ActionListener
			 * @author name
			 *
			 */
			class Reg_ExitLisener implements ActionListener {
				/**
				 * @param the actionpermed of Reg_ExitLisener
				 */
				public void actionPerformed(ActionEvent event) {
					f.dispose();
					frame.setVisible(true);
				}
			}
			Reg_OK.addActionListener(new Reg_OK_Listener());
			Reg_EXIT.addActionListener(new Reg_ExitLisener());
			
		}
	}
	/**
	 * the flightOKListener implements ActionListener
	 * @author name
	 *
	 */
	class flightOKListener implements ActionListener {
		
		/**
		 * @param the actionpermed of flightOKListener
		 */
		public void actionPerformed(ActionEvent event) {
			if(flightList.getSelectedValue() == null) {
				JOptionPane.showMessageDialog(null, "Please select one flight!");
			} else {			
				if (clientformatter == NEW_ClientFormatter.getSingletonInstance()){
					flightLogin.setEnabled(false);
					BookOK.setEnabled(true);
					Reserve.setEnabled(true);
					newCliReg.setEnabled(true);
					//statusTextArea.setText("You hwewewewewewed this ticket.");
					
				} else {
					flightLogin.setEnabled(true);
					BookOK.setEnabled(false);
					Reserve.setEnabled(false);
					//newCliReg.setEnabled(true);
				}
				statusTextArea.setText("Now, we'll provide you with the information of the ticket for detail.");
				code = (String)flightList.getSelectedValue();
				StringTokenizer stk = new StringTokenizer(code, "_");
				flightItem = query.getItem(stk.nextToken());					
			}
		}
	}
	/**
	 * the courseOKListener implements ActionListener
	 * @author name
	 *
	 */
	class courseOKListener implements ActionListener {
		/**
		 * @param the actionpermed of courseOKListener
		 */
		public void actionPerformed(ActionEvent event) {
			classtype = cabinType.getSelectedItem().toString();
			if(leavePlace.getSelectedItem().equals(destination.getSelectedItem())) {
				query.removeAllQuery();
				flightList.setListData(query.getQuery());
				JOptionPane.showMessageDialog(null, "Please choose different course!");
			} else {				
				query.removeAllQuery();
				flightList.setListData(query.getQuery());
				for(Iterator iterator = flightdb.getIterator();iterator.hasNext();) {
					FlightItem flightitem = (FlightItem)iterator.next();
					if(((String)flightitem.getLeftPlace()).equals(leavePlace.getSelectedItem())
							&&((String) flightitem.getArrPlace()).equals(destination.getSelectedItem())) {
							if(flightitem == query.getItem(flightitem.getFlightCode())) {
								return;
							} 	
							query.addQuery(flightitem);
					} 			
				}
				if(query.getNumberOfFlightItem() == 0) {
					JOptionPane.showMessageDialog(null, "Sorry, there isn't the course now!");
					statusTextArea.setText("The course has not created!");
					return;
				}
				flightList.setListData(query.getQuery());
				courseOK.setEnabled(false);
				VIPCLIENT.setEnabled(false);
				CLIENT.setEnabled(false);
				NEW_CLIENT.setEnabled(false);
				flightOK.setEnabled(true);	
				ticketsTextArea.setText(null);
				getReserved.setEnabled(false);
				Reset.setEnabled(true);
				if(query.getNumberOfFlightItem() > 1) {
					statusTextArea.setText("LeavePlace:" + leavePlace.getSelectedItem() + " " + "ArrivePlace:" + destination.getSelectedItem()
							+ "\n" + " We have " + new Integer(query.getNumberOfFlightItem()).toString() + " courses.");
					return;
				}
				//Reserve.setEnabled(false);
				statusTextArea.setText("LeavePlace:" + leavePlace.getSelectedItem() + " " + "ArrivePlace:" + destination.getSelectedItem()
						+ "\n" + " We have " + new Integer(query.getNumberOfFlightItem()).toString() + " course.");
				return;
			}
		}
	}
	/**
	 * the VIPClientListener implements ActionListener
	 * @author name
	 *
	 */
	class VIPClientListener implements ActionListener {
		/**
		 * @param the actionpermed of VIPClientListener
		 */
		public void actionPerformed(ActionEvent event) {
			clientformatter = VIPClientFormatter.getSingletonInstance();
		}
	}
	/**
	 * the ClientListener implements ActionListener
	 * @author name
	 *
	 */
	class ClientListener implements ActionListener {
		/**
		 * @param the actionpermed of ClientListener
		 */
		public void actionPerformed(ActionEvent event) {
			clientformatter = CustomerFormatter.getSingletonInstance();
			
		}
	}
	/**
	 * the New_ClientListener implements ActionListener
	 * @author name
	 *
	 */
	class New_ClientListener implements ActionListener {
		/**
		 * @param the actionpermed of New_ClientListener
		 */
		public void actionPerformed(ActionEvent event) {
			clientformatter = NEW_ClientFormatter.getSingletonInstance();
			//statusTextArea.setText("You hasadasdasdasdasdticket.");
		}
	}
	/**
	 * the ExitButtonListener implements ActionListener
	 * @author name
	 *
	 */
	class ExitButtonListener implements ActionListener {
		/**
		 * @param the actionpermed of ExitButtonListener
		 */
		public void actionPerformed(ActionEvent event) {
			int choice = JOptionPane.showConfirmDialog(null,"Would you like to exit?",
					            "Information",JOptionPane.YES_NO_OPTION);
			if(choice == JOptionPane.YES_OPTION) {
				
				
			
			try {
				BufferedWriter out = new BufferedWriter(new FileWriter("d:/client.txt"));
				//FileWriter out=new FileWriter("client.txt");
				
				for(Iterator i=clientdb.getIterator();i.hasNext();){
					Object object=i.next();
					String result="";
					if(!(object instanceof VIPClient)){
						Client client=(Client)object;
						result="client_";
						result+=client.getName()+"_";
						result+=client.getID()+"_";
						result+=client.getPWD()+"_";
						result+=client.getAddress();
						if(client.getTickit()!=null){
							
							result+="_"+client.getTickit().getClassType()+"_";
							Double a=client.getTickit().getPrice();
							result+=a.toString()+"_";
							result+=client.getFligthItem().getFlightCode()+"_";
							result+=client.getFligthItem().getLeftPlace()+"_";
							result+=client.getFligthItem().getArrPlace()+"_";
							result+=client.getFligthItem().getDate()+"_";
							Integer use=client.getFligthItem().getLength();
							result+=use.toString()+"_";
							
						    use=client.getFligthItem().getCabin().getFirstClass();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getBusinessClass();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getEconomyClass();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getFirstNum();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getBusinessNum();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getEconomyNum();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getVIPNum();
							result+=use.toString()+"_";
							use=client.getFligthItem().getCabin().getVIPYotal();
							result+=use.toString()+"_";
							a=client.getFligthItem().getCabin().getPriceOfFC();
							result+=a.toString()+"_";
							a=client.getFligthItem().getCabin().getPriceOfBC();
							result+=a.toString()+"_";
							a=client.getFligthItem().getCabin().getPriceOfEC();
							result+=a.toString();
							
						}
						//String NEW_LINE = System.getProperty("line.separaton");
						out.write(result);
						out.newLine();
						
						
					}
					else{
						
						VIPClient VIPclient=(VIPClient)object;
						result = "VIPclient_";
						result += VIPclient.getName()+"_";
						result += VIPclient.getID()+"_";
						result += VIPclient.getPWD()+"_";
						result += VIPclient.getAddress();
						if(VIPclient.getTickit()!=null){
							
							result+="_"+VIPclient.getTickit().getClassType()+"_";
							Double a=VIPclient.getTickit().getPrice();
							result+=a.toString()+"_";
							Integer use=VIPclient.getLeftLength();
							result+=use.toString()+"_";
							result += VIPclient.getFligthItem().getFlightCode()+"_";
							result+=VIPclient.getFligthItem().getLeftPlace()+"_";
							result+=VIPclient.getFligthItem().getArrPlace()+"_";
							result+=VIPclient.getFligthItem().getDate()+"_";
							 use=VIPclient.getFligthItem().getLength();
							result+=use.toString()+"_";
							
						    use=VIPclient.getFligthItem().getCabin().getFirstClass();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getBusinessClass();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getEconomyClass();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getFirstNum();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getBusinessNum();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getEconomyNum();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getVIPNum();
							result+=use.toString()+"_";
							use=VIPclient.getFligthItem().getCabin().getVIPYotal();
							result+=use.toString()+"_";
							a=VIPclient.getFligthItem().getCabin().getPriceOfFC();
							result+=a.toString()+"_";
							a=VIPclient.getFligthItem().getCabin().getPriceOfBC();
							result+=a.toString()+"_";
							a=VIPclient.getFligthItem().getCabin().getPriceOfEC();
							result+=a.toString();
							
						}
						//String NEW_LINE = System.getProperty("line.separaton");
						out.write(result);
						out.newLine();
						//String NEW_LINE = System.getProperty("line.separaton");
						
						
					}
					
					
					
				}out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.print("Can not write");
			}
			System.exit(0);
		} else {
				return;
		}
			
		}
	}
	/**
	 * the BookOKListener implements ActionListener
	 * @author name
	 *
	 */
	class BookOKListener implements ActionListener {
		/**
		 * @param the actionpermed of BookOKListener
		 */
		public void actionPerformed(ActionEvent event) {			

		}
	}
	/**
	 * the flightLoginListener implements ActionListener
	 * @author name
	 *
	 */
	class flightLoginListener implements ActionListener {
		/**
		 * @param the actionpermed of flightLoginListener
		 */
		public void actionPerformed(ActionEvent event) {
			
			frame_VIP_Login = new JFrame("Login");
			frame_VIP_Login.setSize(300, 140);
			frame_VIP_Login.setTitle("Login");
			Point location = new Point(400, 260);
			frame_VIP_Login.setLocation(location);
			login = new VIP_Login();
			frame_VIP_Login.setContentPane(login.getPanel());
			password.setText(null);
			frame_VIP_Login.setVisible(true);
		}
	}
	/**
	 * the resetListener implements ActionListener
	 * @author name
	 *
	 */
	class resetListener implements ActionListener {
		/**
		 * @param the actionpermed of resetListener
		 */
		public void actionPerformed(ActionEvent event) {
			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();
			client = null;
			logout.setEnabled(false);
			if(login!=null)
			login.setEnabled(false);
			newCliReg.setEnabled(false);
			getReserved.setEnabled(true);
			Reset.setEnabled(false);
			ticketsTextArea.setText("");
			flightList.setListData(query.getQuery());
		}
	}
	/**
	 * the login_CancelListener implements ActionListener
	 * @author name
	 *
	 */
	class login_CancelListener implements ActionListener {
		/**
		 * @param the actionpermed of login_CancelListener
		 */
		public void actionPerformed(ActionEvent event) {
			
			if (frame_VIP_Login!= null) {
				frame_VIP_Login = null;
			}
			frame_VIP_Login = null;
			if (frame_client!= null) {
				frame_client.dispose();
			}
			
			if (login_reserved!= null) {
				login_reserved.dispose();
			}
			frame.setVisible(true);
		}
	}
	/**
	 * the exitListener implements ActionListener
	 * @author name
	 *
	 */
	class exitListener implements ActionListener {
		/**
		 * @param the actionpermed of exitListener
		 */
		public void actionPerformed(ActionEvent event) {
			query.removeAllQuery();
			flightList.setListData(query.getQuery());
			flightLogin.setEnabled(false);
			frame_client.dispose();
			frame_VIP.dispose();
			frame.setVisible(true);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -