📄 login.java~24~
字号:
package zcgl;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Login extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField txtName = new JTextField();
JPasswordField txtPass = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
Connection con = null;
Statement smt = null;
ResultSet rs = null;
public Login() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel2.setText("用户名:");
jLabel2.setBounds(new Rectangle(62, 33, 62, 37));
jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel3.setText("密码:");
jLabel3.setBounds(new Rectangle(66, 93, 49, 32));
txtName.setBounds(new Rectangle(126, 41, 160, 31));
txtPass.setBounds(new Rectangle(125, 96, 164, 34));
jButton1.setBounds(new Rectangle(73, 151, 93, 36));
jButton1.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jButton1.setText("登陆");
jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(213, 150, 98, 36));
jButton2.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jButton2.setText("退出");
jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
this.getContentPane().add(txtPass);
this.getContentPane().add(jLabel2);
this.getContentPane().add(txtName);
this.getContentPane().add(jLabel3);
this.getContentPane().add(txtPass);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
}
public void jButton1_actionPerformed(ActionEvent actionEvent) {
if (txtName.getText().trim().equals("")) {
JOptionPane.showMessageDialog(null, "用户名不能为空!");
}
else if (String.copyValueOf(txtPass.getPassword()).equals("")) {
JOptionPane.showMessageDialog(null, "密码不能为空!");
}
else
{
try
{
con = new DBConn().getConnection();
smt = con.createStatement();
rs = smt.executeQuery("select * from OPERATOR where name='"+txtName.getText().trim()+"'");
if(rs.next())
{
String pass = rs.getString(2).trim();
if (String.copyValueOf(txtPass.getPassword()).equals(pass))
{
MainFrame frame = new MainFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) /
2);
frame.setVisible(true);
dispose();
}
else
{
JOptionPane.showMessageDialog(null, "密码不正确!");
}
}
else
{
JOptionPane.showMessageDialog(null, "用户名不存在!");
}
}
catch(Exception e)
{
}
}
}
public void jButton2_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
}
class Login_jButton1_actionAdapter implements ActionListener {
private Login adaptee;
Login_jButton1_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton1_actionPerformed(actionEvent);
}
}
class Login_jButton2_actionAdapter implements ActionListener {
private Login adaptee;
Login_jButton2_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton2_actionPerformed(actionEvent);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -