java中ActionListener的问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 08:35:38
public class EmpHandle implements ActionListener {

EmpModel em = new EmpModel();
EmpView ev = new EmpView();

public void actionPerformed( ActionEvent e) {

if (e.getActionCommand() == "增加") {

EmpModel em = new EmpModel();
EmpView ev = new EmpView();
String s1= ev.s1;
String s2 =ev.s2;
String s3= ev.s3;
String s4= ev.s4;

System.out.println(s1);

if (s1.length() == 0 || s2.length() == 0 || s3.length() == 0) {
JOptionPane.showMessageDialog(new JPanel(), "请输入信息", "错误",
JOptionPane.ERROR_MESSAGE);
}
else {
em.setEmpno(s1);
em.SetEname(s2);
em.SetPosition(s3);
em.SetRemarks(s4);
<

这里有问题吧?
EmpView ev = new EmpView();
String s1= ev.s1;
你仅仅初始化一个EmpView类型的对象,却没有给它的属性做设置(你传递的参数 ActionEvent e没有用到啊),这样得到的ev对象只是一个默认状态的对象,不能传递你所需要的信息,因为大部分对象默认初始化的时候,对它的实例变量设为0,引用变量设为NULL,所以,你把ev的S1属性赋值给String s1,s1得到的是0