我试过了,GETTEXT有值,NAME等没值,似乎是赋值问题?
另外这是我用课本上的代码改的,问下getsource是做什么的,我把information = "用户名:"+name+"\n密码:"+password+"\n性别:"+gendar+"\n出生年月:"+birthday;
全部直接换成各gettext()就正常了,那if语句不是没用了吗
class NActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == txt1) {
name += txt1.getText();
}
else if(e.getSource() == password1) {
password += password1.getText();
}
else if(e.getSource() == txt2){
birthday += txt2.getText();
}
else if(e.getSource() == button1) {
if(password1.getText().equals(password2.getText())) {
information = "用户名:"+name+"\n密码:"+password+"\n性别:"+gendar+"\n出生年月:"+birthday;
}
else information = "密码前后输入不一致!";
JOptionPane.showMessageDialog(null,information);
}
else if(e.getSource() == button2) {
System.exit(0);
}
}
}