import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JOptionPane;import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;public class LoginFrame extends JFrame implements ActionListener{

JPanel J_pan;
JLabel lab_name;
JLabel lab_pass;
JTextField text_name;
JPasswordField password;
JButton btn;

public LoginFrame(){
into();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,400);
this.setLocationRelativeTo(this);
this.setVisible(true);
}

public void into(){
this.setTitle("登录");
J_pan=new JPanel();
J_pan=(JPanel)this.getContentPane();
J_pan.setLayout(null);

lab_name=new JLabel("用户名:");
lab_name.setBounds(80,60,50,20);
text_name=new JTextField();
text_name.setBounds(135,60,120,20);
J_pan.add(lab_name);
J_pan.add(text_name);

lab_pass=new JLabel("密码:");
lab_pass.setBounds(80,100,50,20);
password=new JPasswordField();
password.setBounds(135,100,120,20);
J_pan.add(lab_pass);
J_pan.add(password);

btn=new JButton("登录");
btn.setBounds(175,170,80,20);
btn.addActionListener(this);//绑定监听器
J_pan.add(btn);
}  public void actionPerformed(ActionEvent e){
User us=new User();
us.setUserName(text_name.getText());
us.setPassword(password.getText());
us.verify();
if(us.name==true){
JOptionPane.showMessageDialog(this,"恭喜您,登录成功!","成功",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(this,"请输入正确的登录信息。","失败",JOptionPane.ERROR_MESSAGE);
this.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
password.setText("");
text_name.setText("");
text_name.requestFocus();
}
});
}

}

public static void main(String []args){
new LoginFrame();
}
}public class User{
//属性
private String Username;//用户名
private String password;//密码
public boolean name;
//输入输出方法
public void setUserName(String Username){
this.Username=Username;
}
public void setPassword(String password){
this.password=password;
}
public String getUserName(){
return Username;
}
public String getPassword(){
return password;
}
//验证方法
public void verify(){
if(this.Username=="Java" && this.password=="123"){
System.out.println("输入正确");
name=true;
}
else{
System.out.println("输入不正确");
name=false;
} }
}
输入用户名和密码为什么都是错误~~~~
还有当提示填写正确登录信息的时候,用户名和密码都没有清空并且没有获得焦点!
求各位大虾指点指点初学者!