package flight.query;
import flight.assist.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
public class ComprehenQuery extends JPanel implements ActionListener,ItemListener
{
//A bean used to connect to the database and execute SQL operation
static SqlBean sqlBean = new SqlBean();
//*********************************************************************
//Model for the place combobox
private static DefaultComboBoxModel modelPlace = new DefaultComboBoxModel();
//Model for the airfirm combobox
private static DefaultComboBoxModel modelAirFirm = new DefaultComboBoxModel();
//Items for the year combobox
private static Object[] year = {"2004","2005"};
//Items for the month combobox
private static Object[] month = {"1","2","3","4","5","6","7","8","9","10","11","12"};
//Items for the day combobox
private static Object[] day = {"1","2","3","4","5","6","7","8","9","10","11","12",
"13","14","15","16","17","18","19","20","21","22",
"23","24","25","26","27","28","29","30","31"};
private static JComboBox jcbStart = new JComboBox(),jcbFirstArrive = new JComboBox(),
jcbArrive = new JComboBox(),jcbAirFirm = new JComboBox(modelAirFirm),
jcbYear1 = new JComboBox(year),jcbYear2 = new JComboBox(year),
jcbMonth2 = new JComboBox(month),jcbMonth1 = new JComboBox(month),
jcbDay1 = new JComboBox(day),jcbDay2 = new JComboBox(day);
//*********************************************************************
private JRadioButton jrbSingle = new JRadioButton("单程",true),
jrbDouble = new JRadioButton("往返",false),
jrbMutiple = new JRadioButton("联程",false);
//The program should change the content in the label dynamically,
//so we should put the JLabels as the menber varibles
//so that we can change their contents in every method of this class
private JLabel jlStart,jlFirstArrive,jlArrive,
jlTime1,jlTime2,jlAirFirm,
jlReplaceArrive,jlReplaceTime;
//The program should remove and add components into the framework dynamically
//according to the query mode you have selected!
//So we should put the JPanels as the menber varibles
//so that we can remove and add components in the panels in every method of this class
private JPanel jpFirstArriveBox,jpTime2Box,jpReplaceArrive,jpArrive1,jpReplaceTime,jpTime2;
private JButton jbQuery = new JButton("查询");
//Used to the items choosed from each combobox
private String start,firstArrive,arrive,leaveWeek,leaveWeek2,backWeek,airFirm,
leaveYear,leaveMonth,leaveDay,backYear,backMonth,backDay,
leaveYear2,leaveMonth2,leaveDay2;
//Setup GUI in the Constructor method
public ComprehenQuery()
{
jcbAirFirm.addItem("所有");
jcbAirFirm.setSelectedItem("所有");
//Make the time combobox show the present time when you first the program
setDisplayPresentTime();
//*********************************************************************
JPanel jp1 = new JPanel();
jp1.add(jrbSingle);
JPanel jp2 = new JPanel();
jp2.add(jrbDouble);
JPanel jp3 = new JPanel();
jp3.add(jrbMutiple);
JPanel jpRadioButton = new JPanel();
jpRadioButton.setLayout(new GridLayout(5,1));
jpRadioButton.add(new JLabel(" "));
jpRadioButton.add(jp1);
jpRadioButton.add(jp2);
jpRadioButton.add(jp3);
jpRadioButton.add(new JLabel(" "));
ButtonGroup bg = new ButtonGroup();
bg.add(jrbSingle);
bg.add(jrbDouble);
bg.add(jrbMutiple);
//*********************************************************************
JPanel jpStart = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpStart.add(jlStart = new JLabel(" 出发城市:"));
JPanel jpFirstArrive = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpFirstArrive.add(jlFirstArrive = new JLabel(" "));
JPanel jpArrive = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpArrive.add(jlArrive = new JLabel(" 到达城市:"));
JPanel jpTime1Tip = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpTime1Tip.add(jlTime1 = new JLabel(" 出发日期:"));
JPanel jpTime2Tip = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpTime2Tip.add(jlTime2 = new JLabel(" "));
JPanel jpAirFirm = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jpAirFirm.add(jlAirFirm = new JLabel(" 航空公司:"));
JPanel jpLabels = new JPanel();
jpLabels.setLayout(new GridLayout(7,1));
jpLabels.add(jpStart);
jpLabels.add(jpFirstArrive);
jpLabels.add(jpArrive);
jpLabels.add(jpTime1Tip);
jpLabels.add(jpTime2Tip);
jpLabels.add(jpAirFirm);
jpLabels.add(new JLabel(" "));
//*********************************************************************
JPanel jpStartBox = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpStartBox.add(jcbStart);
//***********************
//The combobox "jcbFirstArrive" should be removed from and added into the
//jpFirstArriveBox dynamically,
//so create a panel contains an empty label that used to replace
//the panel that contains the combobox "jcbFirstArrive" when we don't need it
jpReplaceArrive = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpReplaceArrive.add(jlReplaceArrive = new JLabel(" "));
jpArrive1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpArrive1.add(jcbFirstArrive);
jpFirstArriveBox = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
jpFirstArriveBox.add(jpReplaceArrive);
//***********************
JPanel jpArriveBox = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpArriveBox.add(jcbArrive);
JPanel jpTime1Box = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpTime1Box.add(jcbYear1);
jpTime1Box.add(jcbMonth1);
jpTime1Box.add(jcbDay1);
//***********************
//The comboboxes "jcbYear2,jcbMonth2,jcbDay2" should be removed from
//and added into the jpTime2Box dynamically,
//so create a panel contains an empty label that used to replace
//the panel that contains the comboboxes "jcbYear2,jcbMonth2,jcbDay2"
jpReplaceTime = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpReplaceTime.add(jlReplaceTime = new JLabel(" "));
jpTime2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpTime2.add(jcbYear2);
jpTime2.add(jcbMonth2);
jpTime2.add(jcbDay2);
jpTime2Box = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
jpTime2Box.add(jpReplaceTime);
//***********************
JPanel jpAirFirmBox = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpAirFirmBox.add(jcbAirFirm);
JPanel jpButton = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpButton.add(jbQuery);
JPanel jpComboBox = new JPanel();
jpComboBox.setLayout(new GridLayout(7,1));
jpComboBox.add(jpStartBox);
jpComboBox.add(jpFirstArriveBox);
jpComboBox.add(jpArriveBox);
jpComboBox.add(jpTime1Box);
jpComboBox.add(jpTime2Box);
jpComboBox.add(jpA