我就想做一个修改密码的界面,判断两个密码框输入的字符是否一致,明明输入的是一致的,可就是判断不出来,估计是equals的问题,我初学Java,想了半天搞不出来,希望哪位兄弟帮帮忙,改下代码,先谢谢了!
……
final JLabel label = new JLabel();
label.setText("请输入你的新密码:");
label.setBounds(57, 10, 124, 26);
getContentPane().add(label);final JLabel label_1 = new JLabel();
label_1.setText("确认你的密码:");
label_1.setBounds(57, 52, 124, 26);
getContentPane().add(label_1);final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
if (pf1.getPassword().length==0 || pf2.getPassword().length==0) {
JOptionPane.showMessageDialog(null,"请填写完整");
}
else if(pf1.getPassword().equals(pf2.getPassword())){
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/rbac","root","1");
Statement cmd=con.createStatement();
String sqlStr = "update superuser set User_password='"+pf1.getPassword()+"' where User_name in(select User_name from saveshow)";
cmd.executeUpdate(sqlStr);
}
else{
JOptionPane.showMessageDialog(null,"密码输入错误!");
} }catch(Exception ex){}
}
});
button.setText("确 定");
button.setBounds(138, 115, 79, 32);
getContentPane().add(button);
……
数组相等你用equals??
这样试下吧char a[] b[]
String s = new String(a);
String f = new String(b);
if(s.equals(f))
System.out.println("相等");
public char[] getPassword()返回此 TextComponent 中所包含的文本。如果基础文档为 null,则将给出 NullPointerException。为了取得较高的安全性,建议将每个字符设置为零以便在使用后清除返回的字符数组。 返回:
文本