public class CheckinView extends BaseFrame implements ActionListener{
private JButton confirmBtn;
/**
* @Fields backBtn : 返回按钮
*/
private JButton backBtn;
private JTextField IDTextField;
public CheckinView() {
init();
}
private void init() {
ViewBackgroundUtil.setBG(this, "img/bg2.jpg");
JLabel tipslabel = new JLabel("请输入您购票时的订单号或乘机人身份证号!");
tipslabel.setBounds(280, 60, 250, 33);
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("goToselectView");
IDTextField= new JTextField();
IDTextField.setBounds(280, 90, 240, 33);
IDTextField.setToolTipText("请输入账号");
this.add(IDTextField);
this.add(backBtn);
this.add(confirmBtn);
this.add(tipslabel);
}
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 "goToSelectView":
String airNo = IDTextField.getText();
if ("".equals(airNo)) {
JOptionPane.showMessageDialog(CheckinView.this, "请输入订单号或乘机人身份证号!",
"提示信息", JOptionPane.ERROR_MESSAGE);
return;
}else {
SelectView selectview=new SelectView();
SelectView.setVisible(true);
break;}
}
}
}
大佬们求解,按返回没有用,是代码出错了吗
你这个parant好吓人。
btn.getParent().getParent().getParent().getParent().getParent();
直接给个layout不行吗。