标签:
项目名:图书管理系统
作者:李帅
参考:http://blog.csdn.net/sdliujiangbo/article/details/9003655
MainFrame.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//1.先获取用户名和密码
String name = LoginName.getText();
String password = new String(LoginPwd.getPassword());
//2.进行验证
if("admin".equals(name)&&"admin".equals(password))
{
//登陆成功
//隐藏LoginForm,显示MainForm
this.setVisible(false);
}
else
{
//登录失败
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
}
private void formKeyPressed(java.awt.event.KeyEvent evt) {
//敲击键盘登陆
}
private void LoginNameKeyPressed(java.awt.event.KeyEvent evt) {
//敲击键盘登陆
if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0)
{
jButton1.doClick();
}
}
private void LoginPwdKeyPressed(java.awt.event.KeyEvent evt) {
//敲击键盘登陆
if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0)
{
jButton1.doClick();
}
界面效果:
标签:
原文地址:http://www.cnblogs.com/lsbk/p/5559402.html