📄 login_frm.java
字号:
package KcglSys;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
/**
* <p>Title: 库存管理信息系统</p>
* <p>Description: 库存管理信息系统,企业好助手。</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: dragon</p>
* @author ios
* @version 1.0
*/
public class Login_Frm
extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JSeparator jSeparator1 = new JSeparator();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton2 = new JButton();
JButton jButton1 = new JButton();
TitledBorder titledBorder1;
TitledBorder titledBorder2;
JLabel ImgLabel = new JLabel();
JTextField jTextField1 = new JTextField();
//Construct the frame
public Login_Frm() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setIcon(null);
jLabel1.setText("请键入用户名及密码以登录系统");
contentPane.setLayout(xYLayout1);
this.setResizable(false);
this.setSize(new Dimension(399, 208));
this.setTitle("用户登录");
jLabel2.setFont(new java.awt.Font("Dialog", 0, 13));
jLabel2.setText("用户名:");
jLabel3.setFont(new java.awt.Font("Dialog", 0, 13));
jLabel3.setText("密 码:");
jPasswordField1.setText("");
jPasswordField1.setColumns(0);
jButton2.setText("退出");
jButton2.addActionListener(new Login_Frm_jButton2_actionAdapter(this));
jButton1.setText("确认");
jButton1.addActionListener(new Login_Frm_jButton1_actionAdapter(this));
contentPane.setBackground(Color.lightGray);
contentPane.setBorder(titledBorder2);
ImgLabel.setIcon(new ImageIcon("login_pic.png"));
ImgLabel.setText("");
contentPane.add(jSeparator1, new XYConstraints(23, 61, 329, 8));
contentPane.add(jLabel2, new XYConstraints(71, 94, -1, -1));
contentPane.add(jLabel3, new XYConstraints(71, 135, -1, -1));
contentPane.add(jPasswordField1, new XYConstraints(127, 129, 117, -1));
contentPane.add(jButton1, new XYConstraints(298, 88, -1, -1));
contentPane.add(jButton2, new XYConstraints(298, 129, -1, -1));
contentPane.add(jLabel1, new XYConstraints(64, 34, 230, 30));
contentPane.add(ImgLabel, new XYConstraints(25, 30, -1, 30));
contentPane.add(jTextField1, new XYConstraints(127, 92, 117, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
void jButton1_actionPerformed(ActionEvent e) {
//实例化ErrorCheck类,该类是由我们创建的用于检验字符串的合法性
ErrorCheck errmsg = new ErrorCheck();
ResultSet rs = null;
//实例化ConnectDBBean用于查询帐户的有效性,以登陆主界面
ConnectDBBean conndb = new ConnectDBBean();
String name = jTextField1.getText();
String password = jPasswordField1.getText();
//sql查询语句,用于核查用户和密码
String sql = "select * from usersinfo where username='" + name +
"' and password='" + password + "'";
//检查输入是否为空
if (!errmsg.isEmpty(password)) {
try {
rs = conndb.executeQuery(sql); //执行查询
if (rs.next()) { //判断结果集是否存在
//实例化GetFrmCentershow,该类是由我们创建的用于实现窗口中心显示
GetFrmCenterShow gfc = new GetFrmCenterShow();
//实例化Main_frame
Main_Frm frame = new Main_Frm();
//让frame显示在屏幕中心
gfc.get_center(frame);
//frame的显示
frame.show();
//本窗体的退出
this.dispose();
}
else {
//错误提示
JOptionPane.showMessageDialog(null, "对不起,您不是合法用户!");
}
}
catch (SQLException ex) {
System.err.println("sql error!");
}
}
else {
JOptionPane.showMessageDialog(null, "密码不能为空,请正确输入!");
}
}
}
class Login_Frm_jButton2_actionAdapter
implements java.awt.event.ActionListener {
Login_Frm adaptee;
Login_Frm_jButton2_actionAdapter(Login_Frm adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Login_Frm_jButton1_actionAdapter
implements java.awt.event.ActionListener {
Login_Frm adaptee;
Login_Frm_jButton1_actionAdapter(Login_Frm adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -