📄 mmain.java
字号:
package book;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Mmain{
public static void main(String args[]) {
EnterFrame frame = new EnterFrame("管理员登陆",600,450);
frame.setResizable(false);// 设置不可更改大小
frame.setVisible(true); // 设置窗体可见
frame.validate(); // 设置组件可
}
}
//登陆窗体
class EnterFrame extends Mb{
private JLabel icon;
private JTextField user;
private JPasswordField password; // 密码框
private ResultSet rs;
private ButtonIcon ok,close;
EnterFrame(String s, int i, int j) {
super(s, i, j);
con.setLayout(null);
shezhi();
add();
}
void shezhi(){
icon=new JLabel(new ImageIcon("./data/image/heard/dl1.jpg"));
icon.setBounds(0,0,600,450);
user=new JTextField();
user.setBounds(70,337,100,16);
user.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
ok.doClick();
}
});
password=new JPasswordField();
password.setBounds(225,337,100,16);
password.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
ok.doClick();
}
});
ok=new ButtonIcon("登陆");
ok.setBounds(70,365,70,25);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try {
String name,password1;
boolean boo=false;
boolean boo1=true;
if(Juage()){
MainDAO dao=new MainDAO();
rs=dao.getSelect1("select * from dl");
while ((boo = rs.next()) == true) {
name = rs.getString("用户名");
password1 = rs.getString("密码");
if (name.equals(user.getText()) && password1.equals(password.getText())) {
JOptionPane.showMessageDialog(icon, "验证成功!");
boo1=false;
MainFrame f = new MainFrame("图书管理系统",name);
close();
break;
}
}
if(boo1){
JOptionPane.showMessageDialog(icon, "帐号密码有误!!!!");
user.setText("");
password.setText("");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
close=new ButtonIcon("登陆关闭");
close.setBounds(230,365,70,25);
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
int n = JOptionPane.showConfirmDialog(icon, "是否退出系统?", "退出",
JOptionPane.YES_NO_OPTION);
if (n == 0) {
System.exit(0);
}
}
});
}
boolean Juage(){
boolean boo=true;
if(user.getText().equals("")){
JOptionPane.showMessageDialog(icon, "帐号不能为空!!!!");
boo=false;
}
else
if(password.getText().equals("")){
JOptionPane.showMessageDialog(icon, "密码不能为空!!!!");
boo=false;
}
return boo;
}
void add(){
con.add(user);
con.add(password);
con.add(ok);
con.add(close);
con.add(icon);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -