📄 adminwindow.java
字号:
package newLibrary;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import newLibrary.TitleFrame.scanReaderAction;
//import javax.swing.event.*;
import java.sql.*;
public class AdminWindow extends JFrame
{
/**************声明变量************/
private JPanel ContentPane;
private JLabel jlab0 = new JLabel(); //输出“管理员登录”文本;
private JLabel jlab1 = new JLabel(); //输出“帐号”文本
private JLabel jlab2 = new JLabel(); //输出“密码”文本
private JTextField jtextfield1 = new JTextField();
private JPasswordField jpasswordfield = new JPasswordField();
private JButton enter = new JButton(); //“登录”按钮
private JButton exit = new JButton(); //“退出”按钮
private JButton guest = new JButton();
/*定义AdminWindow()方法*/
public AdminWindow()
{
ContentPane = (JPanel)this.getContentPane();
ContentPane.setLayout(null);
this.setTitle("★图书馆管理系统★");
this.setBounds(300,200,400,300);
ContentPane.setBackground(Color.LIGHT_GRAY);
/***********用户登陆界面********/
jlab0.setText("管理员登陆");
jlab0.setBounds(new Rectangle(95, 25, 200, 36));
jlab0.setFont(new Font("Dialog", 1, 20));//设置字体大小
jlab0.setForeground(Color.black);
jlab1.setText("账 号:");
jlab1.setBounds(new Rectangle(115, 85, 35, 20));
jlab1.setForeground(Color.black);
jlab2.setText("密 码:");
jlab2.setBounds(new Rectangle(115, 125, 35, 20));
jlab2.setForeground(Color.black);
jtextfield1.setText("");
jtextfield1.setBounds(new Rectangle(180, 85, 75, 25));
jpasswordfield.setEchoChar('*');//返回要用于回显的字符。默认值为 '*'
jpasswordfield.setText("");
jpasswordfield.setBounds(new Rectangle(180, 125, 75, 25));
enter.setText("登录");
enter.setVisible(true);
enter.setBounds(new Rectangle(110, 180, 75, 25));
enter.addActionListener(new jenter_actionPerformed());//加事件监听
enter.setForeground(Color.black);
enter.setBackground(Color.LIGHT_GRAY);
enter.setFocusable(true);
exit.setText("退出");
exit.setVisible(true);
exit.setBounds(new Rectangle(230, 180, 75, 25));
exit.addActionListener(new jexit_actionPerformed());//加事件监听
exit.setForeground(Color.black);
exit.setBackground(Color.LIGHT_GRAY);
guest.setText("来宾帐户");
guest.setVisible(true);
guest.setBounds(new Rectangle(255, 30, 100, 25));
guest.setFont(new Font("Dialog", 1, 14));
guest.addActionListener(new guestAction("来宾帐户"));//加事件监听
guest.setForeground(Color.black);
guest.setBackground(Color.LIGHT_GRAY);
/*******把控件添加到面板中去*******/
ContentPane.add(jlab0);
ContentPane.add(jlab1);
ContentPane.add(jlab2);
ContentPane.add(jtextfield1);
ContentPane.add(jpasswordfield);
ContentPane.add(enter);
ContentPane.add(exit);
ContentPane.add(guest);
this.setVisible(true);
}
/**********设置动作按钮的监听事件***********/
class jenter_actionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String user = jtextfield1.getText().trim();
String password = jpasswordfield.getText().trim();
/******连接数据库*********/
try {
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=student.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(strurl);
Statement stmt = conn.createStatement();
/****判断用户输入的信息****/
if(user.equals("")|| password.equals(""))
JOptionPane.showMessageDialog(null, "账号或密码不能为空", "警告",
JOptionPane.WARNING_MESSAGE);
else {
/*从数据库中查询用户名和密码*/
ResultSet rs = stmt.executeQuery("select * from user where username='" +
user + "' AND password='" + password + "'");
/*如果信息正确则进行以下操作*/
if(rs.next())
{
JOptionPane.showMessageDialog(null, "登陆成功");
TitleFrame mainjframe = new TitleFrame();
dispose();
}
else
JOptionPane.showMessageDialog(null, "账号或密码输入错误", "警告",
JOptionPane.WARNING_MESSAGE);
jtextfield1.setText("");
jpasswordfield.setText("");
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}
class jexit_actionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
class guestAction extends AbstractAction
{
public guestAction(String name)
{
super(name);
}
public void actionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "欢迎您使用本系统!");
dispose();
FindTitleDialog guest =new FindTitleDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -