📄 loginform.java
字号:
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class LoginForm extends JFrame implements ActionListener {
JButton log, cen;
JTextField usn;
JPasswordField pwd;
public LoginForm() {
super("登陆系统");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.setLayout(null);
JLabel l1 = new JLabel("用户名:");
l1.setBounds(5, 5, 75, 25);
JLabel l2 = new JLabel("密 码:");
l2.setBounds(5, 32, 75, 25);
usn = new JTextField();
usn.setBounds(60, 5, 160, 25);
pwd = new JPasswordField();
pwd.setBounds(60, 32, 160, 25);
p.add(l1);
p.add(usn);
p.add(l2);
p.add(pwd);
log = new JButton("登 录");
log.addActionListener(this);
p.add(log);
log.setBounds(30, 70, 70, 25);
cen = new JButton("取 消");
cen.addActionListener(this);
p.add(cen);
cen.setBounds(120, 70, 70, 25);
this.getContentPane().add(p);
this.setBounds((Gload.de.width-230)/2, (Gload.de.height-135)/2, 230, 135);
this.setResizable(false);
/*Gload.usn = "admin";
Gload.pwd = "admin";
Conn.ConnDB();
new FrmMain().setVisible(true);*/
}
private void logOnPress() {
String s1, s2;
s1 = Gload.getText(usn);
s2 = pwd.getText().trim();
if (s1.equals("") || s1 == null) {
Gload.MSG(this, "请输入用户名");
usn.grabFocus();
return;
}
if (s2.equals("") || s2 == null) {
Gload.MSG(this, "请输入密码");
pwd.grabFocus();
return;
}
Conn.ConnDB();
ResultSet rs = Conn.query("select id from 管理员 where usn='" + s1 + "' and pwd='" + new MD5().hashOfStr(s2) + "'");
try {
if (rs.next()) {
Gload.usn = usn.getText();
Gload.pwd = pwd.getText();
new FrmMain().setVisible(true);
this.hide();
} else {
Gload.MSG(this, "用户或密码不正确");
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private void cenOnPress() {
Gload.exit();
}
public static void main(String[] args) {
new LoginForm().setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (o.equals(this.log))
logOnPress();
else if (o.equals(this.cen))
this.cenOnPress();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -