动作监听中点击按钮没有反应
申请男孩 2020-06-29 06:50:40 package com.databasejdbc;
import java.awt.*;
import com.HotelGui.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.AncestorListener;
import javax.xml.crypto.Data;
import com.HotelGui.MyHotelMainGui;
import com.common.*;
public class CheckOut extends CheckIn implements ActionListener{
JLabel jl;
public final JTextField jtf;
public JButton check_bt,checkout_bt;
public CheckOut(String str1,String path) {
super(str1,path);
jl=new JLabel("退房房间号");
jl.setBounds(250,120, 80, 28);
jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
jl.setForeground(Color.RED);
jtf=new JTextField(10);
jtf.setBounds(330, 120, 60, 28);
cancel_bt.setVisible(false);
checkout_bt=new JButton(new ImageIcon(path));
checkout_bt.setBounds(160, 500, 85, 30);
checkout_bt.setOpaque(false);
checkout_bt.setActionCommand("1");
checkin_bt.setVisible(false);
check_bt=new JButton("查 询");
check_bt.setBounds(410, 120, 70, 28);
check_bt.setOpaque(false);
checkin_bt.setActionCommand("2");
this.add(jl);
this.add(jtf);
this.add(checkout_bt);
this.add(check_bt);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CheckOut co=new CheckOut("客人退房","images\\checkout_bt.jpg");
}
/*===========================JOptionPane.YES_OPTION========================**
* [## public void checkout_Bt(){}] 退房按钮操作
* 参 数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :点击退房,更新数据库中该房间的状态从2为0
*===================================================*/
public void checkout_Bt()
{
DataBaseConnect dc=new DataBaseConnect();
try {
dc.updateData("update room_table set roomatate=0 where roomnum="+Integer.valueOf(jtf.getText()));
dc.updateData("update costomer_table set isliving=0 where roomnum="+Integer.valueOf(jtf.getText()));
} catch (Exception e1) {
e1.printStackTrace();
}
MyHotelMainGui hm=new MyHotelMainGui(1);
hm.updateRoomState();
}
/*===================================================**
* [## public void check_BT(){}] 退房按钮操作
* 参 数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :点击查询,从数据库中返回数据到姐界面
*===================================================*/
public void check_Bt(String str) throws Exception
{
DataBaseConnect dc=new DataBaseConnect();
Vector data=dc.getDataFromCostomer(Integer.valueOf(jtf.getText().trim()));
Vector data1=dc.RoomOperation(Integer.valueOf(jtf.getText().trim()));
if(!data1.get(2).equals(2))
{
JOptionPane.showMessageDialog(this, str);
}
else
{
room_num_jf.setText(data.get(0).toString());
name_jf.setText(data.get(1).toString());
gender_jb.setSelectedItem(data.get(2));
id_jf.setText(data.get(3).toString());
checkin_jf.setText(data.get(4).toString());
checkout_jf.setText(data.get(5).toString());
charge_jf.setText(data.get(6).toString());
despoit_jf.setText(data.get(7).toString());
price_jf.setText(data1.get(3).toString());
room_type_jb.setSelectedItem(data.get(1));
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand().equals("1"))
{
int flag=JOptionPane.showConfirmDialog(null, "已退房!","提示",JOptionPane.PLAIN_MESSAGE);
if(flag==JOptionPane.YES_OPTION)
{
checkout_Bt();
}
return;
}
if(e.getActionCommand().equals("2"))
{
try {
check_Bt("房间未入住!");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}