📄 tuipiao.java
字号:
package flight.tuipiao;
import flight.assist.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class TuiPiao extends JFrame implements ActionListener
{
private JTextField jtfDingDan = new JTextField(15),jtfID = new JTextField(20),
jtfName = new JTextField(8),jtfFlightInfo = new JTextField(27),
jtfChildNum = new JTextField(8),jtfAdultNum = new JTextField(8),
jtfOriginCost = new JTextField(8),jtfTuiPiaoCost = new JTextField(8),
jtfTime1 = new JTextField(8),
jtfTime2 = new JTextField(8),
jtfChildTuiPiaoShu = new JTextField("0",10),
jtfAdultTuiPiaoShu = new JTextField("0",10);
private JButton jbQuery = new JButton("查询"),jbOK = new JButton("退票"),
jbCancel = new JButton("退出"),jbRewrite = new JButton("重填");
private Object[] items = {"15位身份证","18位身份证" };
private JComboBox jcb = new JComboBox(items);
private JLabel jlTime1 = new JLabel(" 出发时间"),jlTime2 = new JLabel(" ");
private String dingdanNum,name,idNum,flight1,flight2,ticketType,leaveTime1,leaveTime2,
childNum,adultNum,cost;
private File file;
private long locationOfRecord;
private SeatInfo seatInfo = new SeatInfo();
private SqlBean sqlBean = new SqlBean();
public TuiPiao()
{
File f = new File(".","data");
f.mkdir();
file = new File(f,"ClientInfo.txt");
jtfName.setEditable(false);
jtfFlightInfo.setEditable(false);
jtfChildNum.setEditable(false);
jtfAdultNum.setEditable(false);
jtfOriginCost.setEditable(false);
jtfTuiPiaoCost.setEditable(false);
jtfTime1.setEditable(false);
jtfTime2.setEditable(false);
//******************************************************************
JLabel jlDingdan = new JLabel("订 单 号 ");
// jlDingdan.setFont(new Font("Times",Font.PLAIN,12));
JLabel jlID = new JLabel(" 身份证号");
// jlID.setFont(new Font("Times",Font.PLAIN,12));
JPanel jpInput = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpInput.setBorder(new TitledBorder("输入信息"));
jpInput.add(jlDingdan);
jpInput.add(jtfDingDan);
jpInput.add(jlID);
jpInput.add(jtfID);
//****************************************************************
JLabel jlName = new JLabel("客户姓名");
JLabel jlFlight = new JLabel(" 航班信息");
JLabel jlChild = new JLabel("儿童票数");
JLabel jlAdult = new JLabel("成人票数");
JLabel jlOriCost = new JLabel("原 票 价");
JLabel jlTuiCost = new JLabel("退 票 价");
JPanel jpTop = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpTop.add(jlName);
jpTop.add(jtfName);
jpTop.add(jlFlight);
jpTop.add(jtfFlightInfo);
JPanel jpNum = new JPanel();
jpNum.setLayout(new GridLayout(2,1));
JPanel jp1 = new JPanel();
jp1.add(jlChild);
jp1.add(jtfChildNum);
JPanel jp2 = new JPanel();
jp2.add(jlAdult);
jp2.add(jtfAdultNum);
jpNum.add(jp1);
jpNum.add(jp2);
JPanel jpCost = new JPanel();
jpCost.setLayout(new GridLayout(2,1));
JPanel jp3 = new JPanel();
jp3.add(jlOriCost);
jp3.add(jtfOriginCost);
JPanel jp4 = new JPanel();
jp4.add(jlTuiCost);
jp4.add(jtfTuiPiaoCost);
jpCost.add(jp3);
jpCost.add(jp4);
JPanel jpTime = new JPanel();
jpTime.setLayout(new GridLayout(2,1));
JPanel jp5 = new JPanel();
jp5.add(jlTime1);
jp5.add(jtfTime1);
JPanel jp6 = new JPanel();
jp6.add(jlTime2);
jp6.add(jtfTime2);
jpTime.add(jp5);
jpTime.add(jp6);
JPanel jpCenter = new JPanel();
jpCenter.setLayout(new BorderLayout());
jpCenter.add(jpNum,BorderLayout.WEST);
jpCenter.add(jpCost,BorderLayout.CENTER);
jpCenter.add(jpTime,BorderLayout.EAST);
JPanel jpInfo = new JPanel();
jpInfo.setBorder(new TitledBorder("基本信息"));
jpInfo.setLayout(new BorderLayout());
jpInfo.add(jpTop,BorderLayout.NORTH);
jpInfo.add(jpCenter,BorderLayout.CENTER);
jlTime2.setVisible(false);
jtfTime2.setVisible(false);
JPanel jpTuiPiao = new JPanel(new FlowLayout(FlowLayout.CENTER));
jpTuiPiao.setBorder(new TitledBorder("退票"));
jpTuiPiao.add(new JLabel("退票数:"));
jpTuiPiao.add(new JLabel("儿童票"));
jpTuiPiao.add(jtfChildTuiPiaoShu);
jpTuiPiao.add(new JLabel("成人票:"));
jpTuiPiao.add(jtfAdultTuiPiaoShu);
JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
jpButtons.setBorder(new TitledBorder("操作"));
jpButtons.add(jbQuery);
jpButtons.add(jbRewrite);
jpButtons.add(jbOK);
jpButtons.add(jbCancel);
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
jp.add(jpInput,BorderLayout.NORTH);
jp.add(jpInfo,BorderLayout.CENTER);
jp.add(jpTuiPiao,BorderLayout.SOUTH);
JPanel jpTotal = new JPanel();
jpTotal.setBorder(new MatteBorder(new ImageIcon("f.gif")));
jpTotal.setLayout(new BorderLayout());
jpTotal.add(jp,BorderLayout.CENTER);
jpTotal.add(jpButtons,BorderLayout.SOUTH);
//******************************************************************
this.getContentPane().add(jpTotal);
jbQuery.addActionListener(this);
jbRewrite.addActionListener(this);
jbOK.addActionListener(this);
jbCancel.addActionListener(this);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
TuiPiao.this.setVisible(false);
TuiPiao.this.dispose();
}
}
);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jbQuery)
query();
else if (e.getSource() == jbRewrite)
rewrite();
else if (e.getSource() == jbOK)
tuiPiao();
else if (e.getSource() == jbCancel)
{
this.setVisible(false);
this.dispose();
}
}
private void query()
{
String dingdan = jtfDingDan.getText().trim();
if (dingdan.length() == 0)
{
JOptionPane.showMessageDialog(null,"订单号不能为空",
"错误信息",JOptionPane.ERROR_MESSAGE);
return;
}
String id = jtfID.getText().trim();
if (id.length() == 0)
{
JOptionPane.showMessageDialog(null,"身份证号不能为空",
"错误信息",JOptionPane.ERROR_MESSAGE);
return;
}
boolean isValid = getClientInfo(dingdan,id);
if (isValid == false)
{
rewrite();
return;
}
else
{
jtfName.setText(name);
jtfChildNum.setText(childNum);
jtfAdultNum.setText(adultNum);
jtfOriginCost.setText(cost);
jtfTuiPiaoCost.setText("退还70%价钱");
if (Integer.parseInt(childNum) == 0)
{
jtfChildTuiPiaoShu.setText("0");
jtfChildTuiPiaoShu.setEditable(false);
}
else
{
jtfChildTuiPiaoShu.setEditable(true);
}
if (Integer.parseInt(adultNum) == 0)
{
jtfAdultTuiPiaoShu.setText("0");
jtfAdultTuiPiaoShu.setEditable(false);
}
else
{
jtfAdultTuiPiaoShu.setEditable(true);
}
if (ticketType.equals("单程"))
{
jlTime1.setText("出发时间");
jtfTime1.setText(leaveTime1);
jlTime2.setVisible(false);
jtfTime2.setVisible(false);
jtfFlightInfo.setText("(单程机票)" + "航班号:" + flight1);
}
else if (ticketType.equals("往返"))
{
jlTime1.setText("出发时间");
jtfTime1.setText(leaveTime1);
jlTime2.setText("返回时间");
jlTime2.setVisible(true);
jtfTime2.setText(leaveTime2);
jtfTime2.setVisible(true);
jtfFlightInfo.setText("(往返机票) " + " 去: " + flight1 + "; 返: " + flight2);
}
else if (ticketType.equals("联程"))
{
jlTime1.setText("第一出发时间");
jtfTime1.setText(leaveTime1);
jlTime2.setText("第二出发时间");
jlTime2.setVisible(true);
jtfTime2.setText(leaveTime2);
jtfTime2.setVisible(true);
jtfFlightInfo.setText("(联程机票) " + "航班1: " + flight1 + "; 航班2: " + flight2);
}
}
}
private void rewrite()
{
jtfDingDan.setText("");
jtfID.setText("");
jtfName.setText("");
jtfFlightInfo.setText("");
jtfChildNum.setText("");
jtfAdultNum.setText("");
jtfOriginCost.setText("");
jtfTuiPiaoCost.setText("");
jtfTime1.setText("");
jtfTime2.setText("");
jtfChildTuiPiaoShu.setText("0");
jtfAdultTuiPiaoShu.setText("0");
jlTime1.setText("出发时间");
jtfChildTuiPiaoShu.setEditable(true);
jtfAdultTuiPiaoShu.setEditable(true);
jlTime2.setVisible(false);
jtfTime2.setVisible(false);
}
private void tuiPiao()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -