代码1
package com.booking.view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.booking.constants.Constants;
import com.booking.entity.Ticket;
import com.booking.model.Booking;
import com.booking.util.ViewBackgroundUtil;
public class CheckinView extends BaseFrame implements ActionListener{
private static final long serialVersionUID = 2870945371327830406L;
private JTextField orderNoOrIdentityNo;
/**
* @Fields identityNo : 身份证号或订单编号
*/
private JButton confirmBtn;
/**
* @Fields confirmBtn : 确认按钮
*/
private JButton backBtn;
/**
* @Fields backBtn : 返回按钮
*/
public JTextField readTicketData() {
return orderNoOrIdentityNo;
}
public CheckinView() {
init();
}
private void init() {
// 设置背景图片
ViewBackgroundUtil.setBG(this, "img/bg2.jpg");
JLabel idLabel = new JLabel("请输入您购票时的订单号或乘机人身份证号:");
idLabel.setBounds(270, 40, 400, 50);
orderNoOrIdentityNo = new JTextField();
orderNoOrIdentityNo.setBounds(270, 100, 250, 33);
orderNoOrIdentityNo.setToolTipText("请输入订单号或乘机人身份证号");
// 实例化返回按钮
backBtn = new CustomButton(160, 480, CustomButton.LEFT);
backBtn.setText("返回");
backBtn.addActionListener(this);
backBtn.setActionCommand("backToMainView");
// 实例化确认按钮
confirmBtn = new CustomButton(460, 480, CustomButton.RIGHT);
confirmBtn.setText("确认");
confirmBtn.addActionListener(this);
backBtn.setActionCommand("确认");
this.add(orderNoOrIdentityNo);
this.add(backBtn);
this.add(confirmBtn);
this.add(idLabel);}
@Override
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
switch (actionCommand) {
case "backToMainView":
this.dispose();
break;
case "确认":
String No=orderNoOrIdentityNo.getText();
Ticket ticket = new Ticket();
ticket.setIdentityNo(No);
Booking bookService = new Booking();
String resultCode =bookService.createBookingInfo(ticket);
if (Constants.MSG_ERR_IDENTITYNO.equals(resultCode)) {
JOptionPane.showMessageDialog(CheckinView.this,"订单编号或身份证号输入错误,请重新输入!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
if (Constants.MSG_ERR_ORDERNO.equals(resultCode)) {
JOptionPane.showMessageDialog(CheckinView.this,"订单编号或身份证号输入错误,请重新输入!","提示信息", JOptionPane.ERROR_MESSAGE);
return;
}
/*if(JOptionPane.showConfirmDialog(null,"确定?", "提示", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
*/
/*CheckinView.this.setVisible(false);*/
CheckinListView view = new CheckinListView();
view.setVisible(true);
break;
}
}
}
代码2
package com.booking.view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import com.booking.util.ViewBackgroundUtil;
public class CheckinListView extends BaseFrame implements ActionListener{
private static final long serialVersionUID = 2870945371327830406L;
/**
* @Fields backBtn : 返回按钮
*/
private JButton backBtn;
/**
* @Fields checkinBtn : 办理按钮
*/
private JButton checkinBtn;
public CheckinListView() {
init();
}
private void init() {
ViewBackgroundUtil.setBG(this, "img/bg2.jpg");
JLabel welcomelabel = new JLabel("购票订单列表");
welcomelabel.setBounds(30, 560, 500, 30);
backBtn = new CustomButton(160, 480, CustomButton.LEFT);
backBtn.setText("返回");
backBtn.addActionListener(this);
backBtn.setActionCommand("backToMainView");
checkinBtn = new CustomButton(460, 480, CustomButton.RIGHT);
checkinBtn.setText("办理");
checkinBtn.addActionListener(this);
this.add(backBtn);
this.add(checkinBtn);}
public void setVisible(boolean b) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
switch (actionCommand) {
case "backToMainView":
//JButton btn = (JButton) e.getSource();
//JFrame f = (JFrame) btn.getParent().getParent().getParent().getParent().getParent();
//f.setVisible(false);
//f.dispose();
this.dispose();
break;
}
}}
测试下是否进入了case "确认": 这个逻辑