package expressdelivery.frame;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
import expressdelivery.dao.Conn;
public class ModifyInfoFrame extends JFrame {
private JLabel l_id, l_rname, l_addr, l_tel, l_sname, l_state;
private JTextField t_id, t_rname, t_addr, t_tel, t_sname;
private JComboBox<String> c_state;
private JButton b_add, b_reset;
public ModifyInfoFrame(String id) {
this.setSize(300, 350);
this.setLocation(350, 300);
this.setTitle("添加商品信息");
init(id);
this.setVisible(true);
}
public void init(String id) {
this.setLayout(new GridLayout(7, 2, 10, 10));
l_id = new JLabel("快递编号", JLabel.CENTER);
l_rname = new JLabel("收件人", JLabel.CENTER);
l_addr = new JLabel("收件地址", JLabel.CENTER);
l_tel = new JLabel("收件人电话", JLabel.CENTER);
l_sname = new JLabel("派送人", JLabel.CENTER);
l_state = new JLabel("派送状态", JLabel.CENTER);
t_id = new JTextField();
t_rname = new JTextField();
t_addr = new JTextField();
t_tel = new JTextField();
t_sname = new JTextField();
c_state = new JComboBox<String>();
c_state.addItem("请选择");
c_state.addItem("未开始派送");
c_state.addItem("正在派送中");
c_state.addItem("已签收");
b_add = new JButton("添加");
b_add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String id = t_id.getText();
String rname = t_rname.getText();
String addr = t_addr.getText();
String tel = t_tel.getText();
String sname = t_sname.getText();
String state = (String) c_state.getSelectedItem();
try {
Conn c = new Conn();
Connection con = c.getConnection();
PreparedStatement sql = con.prepareStatement("update courier set *" + "=? where id =" + id);
sql.setString(1,id);
sql.setString(2,rname);
sql.setString(3,addr);
sql.setString(4,tel);
sql.setString(5,sname);
sql.setString(6,state);
sql.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
new ManagerInfoFrame();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dispose();
}
});
b_reset = new JButton("清空");
b_reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
t_id.setText("");
t_rname.setText("");
t_addr.setText("");
t_tel.setText("");
t_sname.setText("");
}
});
this.add(l_id);
this.add(t_id);
this.add(l_rname);
this.add(t_rname);
this.add(l_addr);
this.add(t_addr);
this.add(l_tel);
this.add(t_tel);
this.add(l_sname);
this.add(t_sname);
this.add(l_state);
this.add(c_state);
this.add(b_add);
this.add(b_reset);
}
}
运行结果经常出现