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

📄 hangkong.java~1~

📁 航班查询与订票系统 用Java与sqlserver2000来编写一个航班查询与订票系统
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
package flight.dingpiao;

import flight.assist.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import javax.swing.border.*;

public class Hangkong
    extends JFrame
    implements ActionListener {
  private String[] string = new String[22];
  private JComboBox boxyear = new JComboBox();
  private JComboBox boxyear1 = new JComboBox();
  private JComboBox boxyear2 = new JComboBox();
  private JComboBox boxmonth = new JComboBox();
  private JComboBox boxmonth1 = new JComboBox();
  private JComboBox boxmonth2 = new JComboBox();
  private JComboBox boxday1 = new JComboBox();
  private JComboBox boxday2 = new JComboBox();
  private JComboBox boxday = new JComboBox();

  //private JComboBox boxadult=new JComboBox();
  private String[] year = {
      " 2004", " 2005"};
  private String[] adult = {
      " 成人 ", " 儿童 ", " 学生 "};
  private String[] month = {
      "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
  private String[] day = {
      "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
      "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
      "25", "26", "27", "28", "29", "30"};
  private JTextField jbtflight = new JTextField(10);
  private JTextField jbtflight1 = new JTextField(10);
  private JTextField jbtflight2 = new JTextField(10);
  private JRadioButton jbrsingle, jbrdouble, jbrmultiple, jbradult, jbrchild;
  private ButtonGroup jbr = new ButtonGroup();
  private ButtonGroup jbr1 = new ButtonGroup();
  private JButton jbtbutton = new JButton("机 票 预 定");
  private JButton jbtreturn = new JButton("返回主页面");
  Color color = new Color(230, 230, 255);
  static JFrame clientFrame = new JFrame();
  static Hangkong frame;
  private Client client = new Client();
  public static boolean open = false;

  //equals to p0
  private JPanel s1, s2;
  private JLabel jblsecondflight = new JLabel("    第二航班号");
  private JLabel jblreturnflight = new JLabel("       返回航班");
  private SeatInfo seatinformation = new SeatInfo();
  int flag = 0;
  int pflag = 0;
  public Hangkong() {
    frame = this;

    string[5] = "单程";
    //	string[12]="single";
    for (int i = 0; i < year.length; i++)
      boxyear.addItem(year[i]);
    for (int i = 0; i < year.length; i++)
      boxyear1.addItem(year[i]);
    for (int i = 0; i < year.length; i++)
      boxyear2.addItem(year[i]);
    for (int i = 0; i < month.length; i++)
      boxmonth.addItem(month[i]);
    for (int i = 0; i < month.length; i++)
      boxmonth1.addItem(month[i]);
    for (int i = 0; i < month.length; i++)
      boxmonth2.addItem(month[i]);
    for (int i = 0; i < month.length; i++)
      boxday.addItem(day[i]);
    for (int i = 0; i < month.length; i++)
      boxday1.addItem(day[i]);
    for (int i = 0; i < month.length; i++)
      boxday2.addItem(day[i]);
      //	for(int i=0;i<adult.length;i++)
//			boxadult.addItem(adult[i]);
      //Panel for the return time
    JPanel p0 = new JPanel();
    p0.setVisible(false);
    display(p0);
    //p0.setBackground(color);
    p0.setLayout(new FlowLayout(FlowLayout.LEFT));
    p0.add(new JLabel("        返回日期"));
    p0.add(boxyear1);
    //boxyear1.setVisible(false);
    p0.add(new JLabel("年"));
    //	jbtmonth1.setHorizontalAlignment(JTextField.RIGHT);
    p0.add(boxmonth1);
    //	jbtday1.setHorizontalAlignment(JTextField.RIGHT);
    p0.add(new JLabel("月"));
    p0.add(boxday1);
    p0.add(new JLabel("日"));

    //Panel for multiple
    JPanel p1 = new JPanel();
    p1.setVisible(false);
    display1(p1);
    //p1.setBackground(color);
    p1.setLayout(new FlowLayout(FlowLayout.LEFT));
    p1.add(new JLabel("第二出发日期:"));
    p1.add(boxyear2);
    p1.add(new JLabel("年"));
    //	jbtmonth2.setHorizontalAlignment(JTextField.RIGHT);
    p1.add(boxmonth2);
    //	jbtday2.setHorizontalAlignment(JTextField.RIGHT);
    p1.add(new JLabel("月"));
    p1.add(boxday2);
    p1.add(new JLabel("日"));
    //Panel starttime

    JPanel p3 = new JPanel();
    //p3.setBackground(color);
    p3.setLayout(new FlowLayout(FlowLayout.LEFT));
    //JLabel starttime
    p3.add(new JLabel("第一出发日期:"));
    p3.add(boxyear);
    p3.add(new JLabel("年"));
    //	jbtmonth.setHorizontalAlignment(JTextField.RIGHT);
    //	jbtmonth.setText("12");
    p3.add(boxmonth);
    //	jbtday.setHorizontalAlignment(JTextField.RIGHT);

    p3.add(new JLabel("月"));
    p3.add(boxday);
    p3.add(new JLabel("日"));
    //Panel style
    JPanel p5 = new JPanel();
    //p5.setBackground(color);
    p5.setLayout(new FlowLayout(FlowLayout.LEFT));
    //style
    p5.add(new JLabel("机票类型:                 "));
    p5.add(jbrsingle = new JRadioButton("单程", true));
    p5.add(jbrdouble = new JRadioButton("往返", false));
    p5.add(jbrmultiple = new JRadioButton("联票   ", false));
    //	p5.add(boxadult);
    //jbrsingle.setBackground(color);
    //jbrdouble.setBackground(color);
    //jbrmultiple.setBackground(color);
    jbr.add(jbrsingle);
    jbr.add(jbrdouble);
    jbr.add(jbrmultiple);

    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout(FlowLayout.LEFT));
    //p6.setBackground(color);
    p6.add(jbtbutton);
    p6.add(jbtreturn);
    JPanel p8 = new JPanel();
    //p8.setBackground(color);
    p8.setLayout(new FlowLayout(FlowLayout.LEFT));
    //the firstflight
    p8.add(new JLabel("第一航班号:   "));
    p8.add(jbtflight);
    p8.add(jblreturnflight);
    p8.add(jbtflight1);
    p8.add(jblsecondflight);
    p8.add(jbtflight2);
    jblsecondflight.setVisible(false);
    jbtflight1.setVisible(false);
    jbtflight2.setVisible(false);
    jblreturnflight.setVisible(false);
    JPanel p7 = new JPanel();
    //p7.setBackground(color);
    p7.setBorder(new MatteBorder(new ImageIcon("f.gif")));
    p7.setLayout(null);
    p7.add(p0);
    p7.add(p1);
    p7.add(p3);
    p7.add(p5);
    p7.add(p6);
    p7.add(p8);
    p3.reshape(50, 30, 350, 30);
    p0.reshape(50, 70, 350, 30);
    p1.reshape(50, 70, 350, 30);
    p8.reshape(50, 110, 350, 30);
    p5.reshape(50, 150, 350, 40);
    p6.reshape(120, 200, 250, 30);
    getContentPane().add(p7, BorderLayout.CENTER);
    getContentPane().setBackground(new Color(255, 255, 230));
    jbtbutton.addActionListener(this);
    jbtreturn.addActionListener(this);
    jbrsingle.addActionListener(this);
    jbrdouble.addActionListener(this);
    jbrmultiple.addActionListener(this);

    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        Hangkong.this.setVisible(false);
        Hangkong.this.dispose();
      }
    }
    );
  }

  //set panel//s1 for return
  public void display(JPanel p) {
    s1 = p;

  }

  //set label//s2 for multiple
  public void display1(JPanel p) {
    s2 = p;
  }

  String otherchoice = new String(" ");
  String dotherchoice = new String(" ");
  String motherchoice = new String(" ");
  boolean isFull = false;
  public void actionPerformed(ActionEvent e) {
    String year1 = new String(boxyear.getSelectedItem().toString().trim());
    String month1 = new String(boxmonth.getSelectedItem().toString().trim());
    String day1 = new String(boxday.getSelectedItem().toString().trim());
    String year2 = new String(boxyear1.getSelectedItem().toString().trim());
    String month2 = new String(boxmonth1.getSelectedItem().toString().trim());
    String day2 = new String(boxday1.getSelectedItem().toString().trim());
    string[2] = year1 + "年" + month1 + "月" + day1 + "日";
    string[3] = year1 + month1 + day1;
    string[4] = jbtflight.getText().trim();
    string[9] = year2 + "年" + month2 + "月" + day2 + "日";
    string[10] = year2 + month2 + day2;
    string[11] = jbtflight1.getText().trim();
    string[16] = jbtflight2.getText().trim();
    String year3 = new String(boxyear2.getSelectedItem().toString().trim());
    String month3 = new String(boxmonth2.getSelectedItem().toString().trim());
    String day3 = new String(boxday2.getSelectedItem().toString().trim());
    string[17] = year3 + month3 + day3;
    string[18] = year3 + "年" + month3 + "月" + day3 + "日";

    //book the ticket
    if (e.getSource() == jbtbutton) {
      otherchoice = " ";
      dotherchoice = " ";
      isFull = seatinformation.isFull(string[4], string[3]);
      int sflight = singleflight();
      int dflight = 0;
      int mflight = 0;

      String year = string[3].substring(0, 4);
      String month = string[3].substring(4, 6);
      String day = string[3].substring(6, 8);
      boolean before = isTimeValid(year, month, day);

      if (before) {
        if (jbrsingle.isSelected()) {
          if (sflight == 1) {
            JOptionPane.showMessageDialog(this, "航班号不能为空!",
                                          "错误信息", JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");
          }
          else if (sflight == 2) {
            JOptionPane.showMessageDialog(this,
                                          "你要预定的航班已经满座!\n您可以改定同一天的航班:\n" + otherchoice,
                                          "客户信息",
                                          JOptionPane.INFORMATION_MESSAGE);
            jbtflight.setText("");
          }
          else if (sflight == 3) {
            JOptionPane.showMessageDialog(this,
                "您要预定的航班已经满座了!\n而且当天其他航班也已无票售!\n建议您重新选择航班日期",
                                          "错误信息", JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");

          }
          else if (sflight == 4) {
            JOptionPane.showMessageDialog(this, "没有此次航班,请您重新查阅!",
                                          "错误信息", JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");
          }
          else {
            clientFrame.getContentPane().add(client.panel(string));
            clientFrame.setTitle("客户资料");
            clientFrame.setSize(450, 460);
            clientFrame.setVisible(true);
            this.setVisible(false);

            client.jbtname.setText("");
            client.jbtid.setText("");
            client.jbtqq.setText("");
            client.jbtps.setText("");
            client.jbttelephone.setText("");
            client.jbtadultticketnumber.setText("1");
            client.jbtchildticketnumber.setText("1");
          }
        }
        else if (jbrdouble.isSelected()) {
          isFull = seatinformation.isFull(string[11], string[10]);
          dflight = doubleflight();
          if (sflight == 1) {
            JOptionPane.showMessageDialog(this, "第一航班号不能为空!", "错误信息",
                                          JOptionPane.ERROR_MESSAGE);
          }
          else if (sflight == 2) {
            JOptionPane.showMessageDialog(this,
                                          "你要预定的第一航班号已经满座!\n您可以改定同一天的航班:\n" +
                                          otherchoice, "客户信息",
                                          JOptionPane.INFORMATION_MESSAGE);
            jbtflight.setText("");
          }
          else if (sflight == 3) {
            JOptionPane.showMessageDialog(this,
                "您要预定的第一航班已经满座了!\n而且当天其他航班也已无票售!\n建议您重新选择第一航班日期", "错误信息",
                                          JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");

          }
          else if (sflight == 4) {
            JOptionPane.showMessageDialog(this, "没有第一航班号,请您重新查阅!", "错误信息",
                                          JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");
          }
          else {
            if (dflight == 1) {
              JOptionPane.showMessageDialog(this, "返回航班号不能为空!", "错误信息",
                                            JOptionPane.ERROR_MESSAGE);

            }
            else if (dflight == 2) {
              JOptionPane.showMessageDialog(this,
                                            "你要预定的返回航班号已经满座!\n您可以改定同一天的航班:\n" +
                                            otherchoice, "客户信息",
                                            JOptionPane.INFORMATION_MESSAGE);
              jbtflight1.setText("");
            }
            else if (dflight == 3) {
              JOptionPane.showMessageDialog(this,
                  "您要预定的返回航班号已经满座了!\n而且当天其他航班也已无票售!\n建议您重新选择返回日期", "错误信息",
                                            JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else if (dflight == 4) {
              JOptionPane.showMessageDialog(this, "不存在您要预定的返回班号,请您重新查阅!",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else if (dflight == 5) {
              JOptionPane.showMessageDialog(this, "返回航班号与第一航班号不匹配\n请重新输入返回航班号!",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else {
              clientFrame.getContentPane().add(client.panel(string));
              clientFrame.setSize(450, 460);
              clientFrame.setTitle("客户资料");
              clientFrame.setVisible(true);
              this.setVisible(false);
            }
          }
        }

⌨️ 快捷键说明

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