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

📄 comprehenquery.java

📁 功能齐全的航班订票系统,可以完成查询,修改,订航班,记录信息等多项功能.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    				jcb.removeItem("30");
    			}
    			else if (jcb.getItemCount() == 28)
    			{
    				jcb.addItem("29");
    			}
    		}
    		   //The year is not leap year
    		else 
    		{
    			if (jcb.getItemCount() == 29)
    			{
    				jcb.removeItem("29");
    			}
    			else if (jcb.getItemCount() == 30)
    			{
    				jcb.removeItem("29");
    				jcb.removeItem("30");
    			}
    			else if (jcb.getItemCount() == 31)
    			{
    				jcb.removeItem("29");
    				jcb.removeItem("30");
    				jcb.removeItem("31");
    			}
    		}
    	}
    	   //There are 31 days in the left months    	
    	else 
    	{
    		if (jcb.getItemCount() == 28)
    		{
    		    jcb.addItem("29");
    		    jcb.addItem("30");
    		    jcb.addItem("31");	
    		}
    		else if (jcb.getItemCount() == 29)
    		{
    			jcb.addItem("30");
    			jcb.addItem("31");    			
    		}
    		else if (jcb.getItemCount() == 30)
    		{
    			jcb.addItem("31");
    		}    		
    	}
    }
    
       //The monitor method for the time combobox
    public void itemStateChanged(ItemEvent e)
    {
    	   //Change the items in the day combobox dynamically
           //according to the year and month that you choose
    	if (e.getSource() == jcbYear1 || e.getSource() == jcbMonth1)
    	{
    		String year = (String)jcbYear1.getSelectedItem();
    		String month = (String)jcbMonth1.getSelectedItem();    		
    		   
    		updateDay(year,month,jcbDay1);
    	}
    	   //The same reason as the above one
    	if (e.getSource() == jcbYear2 || e.getSource() == jcbMonth2)
    	{
    		String year = (String)jcbYear2.getSelectedItem();
    		String month = (String)jcbMonth2.getSelectedItem();
    		
    		updateDay(year,month,jcbDay2);
    	}
    }
    
       //An inner class for the JRadioButton listener
    class RadioListener implements ActionListener
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		   //Remove and add components into the framework dynamically
               //according to the query mode you have selected! 
               
               //If you choose the one way query mode   		  
    		if (jrbSingle.isSelected())
    		{
    			jlFirstArrive.setText("            ");
    			   //Remove the present components in the jpFirstArriveBox panel
    			jpFirstArriveBox.removeAll(); 
    			   //Add the designate component into the panel in the designate query mode
    			jpFirstArriveBox.add(jpReplaceArrive);
    			   //Use the method repaint() so that the component you just add into the panel
    			   //can be showed immediately
    			jpFirstArriveBox.repaint();
    			
    			jlArrive.setText("    到达城市:");
    			jlTime1.setText("    出发日期:");
    			jlTime2.setText("            ");
    			
    			jpTime2Box.removeAll();
    			jpTime2Box.add(jpReplaceTime); 
    			jpTime2Box.repaint();  			
    		}
    		   //If you choose the out and home query mode
    		else if(jrbDouble.isSelected())
    		{
    			jlFirstArrive.setText("            ");
    			jpFirstArriveBox.removeAll();
    			jpFirstArriveBox.add(jpReplaceArrive);
    			jpFirstArriveBox.repaint();
    			
    			jlArrive.setText("    到达城市:");    			
    			jlTime1.setText("    出发日期:");
    			jlTime2.setText("    返程日期:");
    			
    			jpTime2Box.removeAll();
    			jpTime2Box.add(jpTime2);
    			jpTime2Box.repaint();
    		}
    		   //If you choose the mutiple way query mode
    		else if (jrbMutiple.isSelected())
    		{
    			jlFirstArrive.setText("第一到达城市:");
    			jpFirstArriveBox.removeAll();
    			jpFirstArriveBox.add(jpArrive1);
    			jpFirstArriveBox.repaint();
    			
    			jlArrive.setText("第二到达城市:");
    			jlTime1.setText("第一出发日期:");
    			jlTime2.setText("第二出发日期:");
    			
    			jpTime2Box.removeAll();
    			jpTime2Box.add(jpTime2);
    			jpTime2Box.repaint();
    		}    		
    	}
    }
    
       //The monitor method for the button "jbQuery"
    public void actionPerformed(ActionEvent e)
    {
    	   //According to the query mode you choose,the operation is different
    	   
    	   //If you choose the one way query mode  
        if (jrbSingle.isSelected())
        {
        	   //Get the start place
        	start = (String)jcbStart.getSelectedItem();
        	   //Trim the space at the side of the string
        	start = start.trim();
        	
        	   //Get the destination
        	arrive = (String)jcbArrive.getSelectedItem();
        	arrive = arrive.trim();
        	
        	   //Get the leave time
        	leaveYear = (String)jcbYear1.getSelectedItem();
        	leaveMonth = (String)jcbMonth1.getSelectedItem();
        	leaveDay = (String)jcbDay1.getSelectedItem();
        	
        	   //Judge whether the time you choose is valid or not
        	if (!isTimeValid(leaveYear,leaveMonth,leaveDay))
        	{
        		   //If the time is not valid,show error message to the user
        		JOptionPane.showMessageDialog(null,"已经过了出发时间,请重新设定并查询",
        		                              "错误信息",JOptionPane.ERROR_MESSAGE);
        		return;
        	}
        	
        	   //The method timeToWeek is used to turn the designate day into the weekday
        	   //Like turn "2004,12,25" into 6(Saturday)
        	leaveWeek = timeToWeek(leaveYear,leaveMonth,leaveDay);
        	
        	   //Get which air firm you want to take
        	airFirm = (String)jcbAirFirm.getSelectedItem();
        	airFirm = airFirm.trim();
        	
        	   //Do the query work
        	executeSingleQuery();
        }
           //If you choose the out and home way query mode
        else if(jrbDouble.isSelected())
        {
        	start = (String)jcbStart.getSelectedItem();
        	start = start.trim();        	   
        	
        	arrive = (String)jcbArrive.getSelectedItem();
        	arrive = arrive.trim();
        	
        	   //Get the leave time
        	leaveYear = (String)jcbYear1.getSelectedItem();
        	leaveMonth = (String)jcbMonth1.getSelectedItem();
        	leaveDay = (String)jcbDay1.getSelectedItem();
        	   //Get the back time
        	backYear = (String)jcbYear2.getSelectedItem();
        	backMonth = (String)jcbMonth2.getSelectedItem();
            backDay = (String)jcbDay2.getSelectedItem();
        	
        	   //Judge whether the time you choose is valid or not
        	if (!isTimeValid(leaveYear,leaveMonth,leaveDay))
        	{
        		JOptionPane.showMessageDialog(null,"已经过了出发时间,请重新设定并查询",
        		                              "错误信息",JOptionPane.ERROR_MESSAGE);
        		return;
        	}
        	
        	if (!isTimeValid(leaveYear,leaveMonth,leaveDay,backYear,backMonth,backDay))
        	{
        		JOptionPane.showMessageDialog(null,"返程日期不能比出发日期早,请重新设定并查询",
        		                              "错误信息",JOptionPane.ERROR_MESSAGE);
        		return;
        	}
        	
        	leaveWeek = timeToWeek(leaveYear,leaveMonth,leaveDay);
        	backWeek = timeToWeek(backYear,backMonth,backDay);
        	
        	airFirm = (String)jcbAirFirm.getSelectedItem();
        	airFirm = airFirm.trim();
        	
        	executeDoubleQuery();
        }
           //If you choose the mutiple way query mode
        else if (jrbMutiple.isSelected())
        {
        	start = (String)jcbStart.getSelectedItem();
        	start = start.trim();
        	   //Get the midway destination 
        	firstArrive = (String)jcbFirstArrive.getSelectedItem();
        	firstArrive = firstArrive.trim();
        	   //Get the final destination
        	arrive = (String)jcbArrive.getSelectedItem();
        	arrive = arrive.trim();
        	   
        	   //Get the leave time for the start city
        	leaveYear = (String)jcbYear1.getSelectedItem();
        	leaveMonth = (String)jcbMonth1.getSelectedItem();
        	leaveDay = (String)jcbDay1.getSelectedItem();
        	   //Get the leave time for the midway city
        	leaveYear2 = (String)jcbYear2.getSelectedItem();
        	leaveMonth2 = (String)jcbMonth2.getSelectedItem();
        	leaveDay2 = (String)jcbDay2.getSelectedItem();
        	
        	   //Judge whether the time you choose is valid or not
        	if (!isTimeValid(leaveYear,leaveMonth,leaveDay))
        	{
        		JOptionPane.showMessageDialog(null,"已经过了出发时间,请重新设定并查询",
        		                              "错误信息",JOptionPane.ERROR_MESSAGE);
        		return;
        	}
        	
        	if (!isTimeValid(leaveYear,leaveMonth,leaveDay,leaveYear2,leaveMonth2,leaveDay2))
        	{
        		JOptionPane.showMessageDialog(null,"返程日期不能比出发日期早,请重新设定并查询",
        		                              "错误信息",JOptionPane.ERROR_MESSAGE);
        		return;
        	}
        	
        	leaveWeek = timeToWeek(leaveYear,leaveMonth,leaveDay);
        	leaveWeek2 = timeToWeek(leaveYear2,leaveMonth2,leaveDay2);
        	
        	airFirm = (String)jcbAirFirm.getSelectedItem();
        	airFirm = airFirm.trim();
        	
        	executeMutipleQuery();
        }        	
    }  
    
       //The method used to judge whether the time the you choose is valid or nor
       //If the time you choose is earlier than the present time ,it isn;t valid
    private boolean isTimeValid(String year,String month,String day)
    {
    	int y = Integer.parseInt(year);
    	int m = Integer.parseInt(month);
    	int d = Integer.parseInt(day);
    	
    	   //Get the present time
    	Calendar cal = Calendar.getInstance();
    	 
    	cal.setTime(new java.util.Date());
    	
    	int py = cal.get(Calendar.YEAR);
    	int pm = cal.get(Calendar.MONTH) + 1;
    	int pd = cal.get(Calendar.DAY_OF_MONTH);
    	
    	if (y == py)
    	{
    		if (m < pm)
    		   return false;
    		else if(d < pd)
    		   return false;
    	}
    	
    	return true;
    }  
    
       //The method alse used to judge whether the time the you choose is valid or nor
       //But it is used to determine whether the leave time for the start city is later
       //than the leave time for the midway city! If so ,it isn't valid
    private boolean isTimeValid(String year1,String month1,String day1,
                                String year2,String month2,String day2)
    {
    	int y1 = Integer.parseInt(year1);
    	int m1 = Integer.parseInt(month1);
    	int d1 = Integer.parseInt(day1);
    	
    	int y2 = Integer.parseInt(year2);
    	int m2 = Integer.parseInt(month2);
    	int d2 = Integer.parseInt(day2);
    	
    	if (y1 < y2)
    	   return true;
    	else if (y1 == y2)
    	{
    		if (m1 < m2)
    		   return true;
    		else if (m1 == m2)
    		{
    			if (d1 < d2)
    			   return true;
    			else if (d1 == d2)
    			   return true;
    			else 
    			   return false;
    		}
    		else 
    		   return false;
    	}
    	else 

⌨️ 快捷键说明

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