📄 ticketbook.java~75~
字号:
package flight.ticketbook;
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 TicketBook
extends JFrame
implements ActionListener, ItemListener {
DataBaseManager dbManager = DataBaseManager.getInstance();
private String[] string = new String[22];
/*
string[3]----------------日期
string[4]----------------航班号
string[5]----------------类型:单程、双程、联程
string[16]----------------订单号
string[10]----------------返程日期
string[11]----------------返程航班号
string[12]----------------姓名
string[13]----------------身份证号
string[14]----------------成人票数
string[15]----------------儿童票数
string[21]----------------总价
*/
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 String[] year = {
"2006", "2007", "2008"};
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", "31"};
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("返回主页面");
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;
String startplace = new String();
String endplace = new String();
public TicketBook() {
string[5] = "单程";
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 < day.length; i++)
boxday.addItem(day[i]);
for (int i = 0; i < day.length; i++)
boxday1.addItem(day[i]);
for (int i = 0; i < day.length; i++)
boxday2.addItem(day[i]);
JPanel p0 = new JPanel();
p0.setVisible(false);
display(p0);
p0.setLayout(new FlowLayout(FlowLayout.LEFT));
p0.add(new JLabel(" 返回日期"));
p0.add(boxyear1);
p0.add(new JLabel("年"));
p0.add(boxmonth1);
p0.add(new JLabel("月"));
p0.add(boxday1);
p0.add(new JLabel("日"));
//Panel for multiple
JPanel p1 = new JPanel();
p1.setVisible(false);
display1(p1);
p1.setLayout(new FlowLayout(FlowLayout.LEFT));
p1.add(new JLabel("第二出发日期:"));
p1.add(boxyear2);
p1.add(new JLabel("年"));
p1.add(boxmonth2);
p1.add(new JLabel("月"));
p1.add(boxday2);
p1.add(new JLabel("日"));
//Panel starttime
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.LEFT));
//JLabel starttime
p3.add(new JLabel("第一出发日期:"));
p3.add(boxyear);
p3.add(new JLabel("年"));
p3.add(boxmonth);
p3.add(new JLabel("月"));
p3.add(boxday);
p3.add(new JLabel("日"));
//Panel style
JPanel p5 = new JPanel();
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));
jbr.add(jbrsingle);
jbr.add(jbrdouble);
jbr.add(jbrmultiple);
JPanel p6 = new JPanel();
p6.setLayout(new FlowLayout(FlowLayout.LEFT));
p6.add(jbtbutton);
p6.add(jbtreturn);
JPanel p8 = new JPanel();
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.setBorder(new MatteBorder(new ImageIcon("border.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);
boxyear.addItemListener(this);
boxyear1.addItemListener(this);
boxyear2.addItemListener(this);
boxmonth.addItemListener(this);
boxmonth1.addItemListener(this);
boxmonth2.addItemListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TicketBook.this.setVisible(false);
TicketBook.this.dispose();
}
}
);
setDisplayPresentTime();
this.setSize(430, 300);
this.setResizable(false);
this.setTitle("国内机票实时速定");
}
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) {
//book the ticket
if (e.getSource() == jbtbutton) {
int conditionSatisfied = 0;
if (jbrsingle.isSelected()) {
conditionSatisfied = singleflight();
}
else if (jbrdouble.isSelected()) {
conditionSatisfied = doubleflight();
}
else if (jbrmultiple.isSelected()) {
JOptionPane.showMessageDialog(this, "联程订票功能尚未开通!",
"提示信息", JOptionPane.WARNING_MESSAGE);
return;
}
if (conditionSatisfied == 1) {
ClientFrame clientFrame = new ClientFrame();
clientFrame.initTextField(string);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); //屏幕大小
clientFrame.setLocation( (d.width - clientFrame.getSize().width) /
2,
(d.height - clientFrame.getSize().height) /
2);
clientFrame.show();
}
}
if (e.getSource() == jbtreturn) {
this.setVisible(false);
this.dispose();
}
if (e.getSource() == jbrsingle) {
string[11] = jbtflight1.getText().trim();
string[5] = "单程";
s1.setVisible(false);
s2.setVisible(false);
jblsecondflight.setVisible(false);
jbtflight1.setVisible(false);
jblreturnflight.setVisible(false);
jbtflight2.setVisible(false);
}
if (e.getSource() == jbrdouble) {
string[5] = "往返";
s2.setVisible(false);
s1.setVisible(true);
jblreturnflight.setVisible(true);
jbtflight1.setVisible(true);
jblsecondflight.setVisible(false);
jbtflight2.setVisible(false);
}
if (e.getSource() == jbrmultiple) {
string[5] = "联程";
s1.setVisible(false);
jblreturnflight.setVisible(false);
jbtflight1.setVisible(false);
s2.setVisible(true);
jblsecondflight.setVisible(true);
jbtflight2.setVisible(true);
}
}
public int singleflight() {
if (jbtflight.getText().trim().length() == 0) {
JOptionPane.showMessageDialog(this, "航班号不能为空!",
"错误信息", JOptionPane.ERROR_MESSAGE);
return 0;
}
string[4] = jbtflight.getText().trim();
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[3] = year1 + month1 + day1;
string[2] = year1 + "年" + month1 + "月" + day1 + "日";
if (!this.isTimeValid(year1, month1, day1)) {
JOptionPane.showMessageDialog(null, "对不起,不能预定以前的票了",
"客户信息", JOptionPane.ERROR_MESSAGE);
return 0;
}
ResultSet rs = dbManager.getResult("select * from flight where flight='" +
string[4] + "'");
try {
if (!rs.next()) {
JOptionPane.showMessageDialog(this, "没有第一航班号,请您重新查阅!",
"错误信息", JOptionPane.ERROR_MESSAGE);
jbtflight.setText("");
return 0;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
if (!this.isFlightPresent(string[4], string[3])) {
JOptionPane.showMessageDialog(null, "对不起,这一天没有这个航班",
"客户信息", JOptionPane.ERROR_MESSAGE);
jbtflight.setText("");
return 0;
}
if (seatinformation.isFull(string[4], string[3])) {
JOptionPane.showMessageDialog(this, "你要预定的航班已经满座!请您改选其它航班",
"客户信息", JOptionPane.INFORMATION_MESSAGE);
jbtflight.setText("");
return 0;
}
String sql =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -