import java.awt.event.ActionEvent;
/**
登录窗口
@author wen
/
public class LoginView extends JFrame{
//private JFrame frame;
/**
/**
public void run() {
try {
LoginView window = new LoginView();
window.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});/**
/**
public void actionPerformed(ActionEvent e) {
System.out.println("用户名:"+textField.getText()+",密码:"+passwordField.getText());
String userName = textField.getText().trim();
String password = new String(passwordField.getPassword()).trim();
if (userName == null || "".equals(userName)) {
JOptionPane.showMessageDialog(null, "登录名不能为空");
return;
}
if (password == null || "".equals(password)) {
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
try {
if (Database.userLogin(userName, password)) {
dispose();
MainView mv = new MainView();
//mv.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "登录失败,请核对登录信息");
return;
}
} catch(Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "登录失败");
return;
}
}
});就是swing窗体的车辆管理系统登陆操作。根据用户输入的用户名和密码进行空判断,不为空的时候,再去数据库查询,当前用户是否存在,如果用户名或密码错误,则提示登录失败。