📄 logon.java
字号:
package yarn;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.awt.Dimension;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class LogOn extends JFrame {
static String EID = null;
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
public LogOn() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout2);
jButton2.setText("取消");
jLabel1.setText("用户名");
jLabel2.setText("密码");
jButton1.setText("确定");
jButton1.addActionListener(new LogOn_jButton1_actionAdapter(this));
xYLayout2.setWidth(640);
xYLayout2.setHeight(480);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(jLabel1, new XYConstraints(243, 168, 40, -1));
this.getContentPane().add(jTextField1,
new XYConstraints(304, 164, 120, 24));
this.getContentPane().add(jButton2, new XYConstraints(340, 289, 84, 26));
this.getContentPane().add(jButton1, new XYConstraints(236, 289, 84, 26));
this.getContentPane().add(jPasswordField1,
new XYConstraints(304, 226, 120, 25));
this.getContentPane().add(jLabel2, new XYConstraints(243, 231, 29, -1));
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
LogOn logon = new LogOn();
logon.setSize(new Dimension(640, 480));
logon.setVisible(true);
}
public void jButton1_actionPerformed(ActionEvent e) {
//获取用户框和密码框数据
// JOptionPane.showMessageDialog(this, "用户名或密码错误", "错误",
// JOptionPane.ERROR_MESSAGE);
String acc = jTextField1.getText();
String pass = new String(jPasswordField1.getPassword());
if(!acc.equals("")&&!pass.equals(""))
{
try {
JDBCFile jf = new JDBCFile();
ResultSet rs1 = jf.executeQuery(
"select Password from Accounts where Account = '" + acc +
"'");
if(rs1.next())
{
if (rs1.getString("Password").equals(String.valueOf(pass.hashCode()))) {
rs1 = jf.executeQuery(
"select Elimit,EID from Accounts where Account = '" + acc +
"'");
rs1.next();
if (rs1.getString("Elimit").equals("gu")) {
this.dispose();
jf = new JDBCFile("gu", "");
JFrame jframe = new YarnSystemFrame(jf);
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = jframe.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
jframe.setLocation((screenSize.width -
frameSize.width) / 2,
(screenSize.height -
frameSize.height) / 2);
jframe.setVisible(true);
} else if (rs1.getString("Elimit").equals("sa")) {
EID = rs1.getString("EID");
this.dispose();
jf = new JDBCFile("sa", "12");
JFrame jframe = new YarnSystemFrame(jf);
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = jframe.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
jframe.setLocation((screenSize.width -
frameSize.width) / 2,
(screenSize.height -
frameSize.height) / 2);
jframe.setVisible(true);
} else if (rs1.getString("Elimit").equals("ma")) {
jf.close();
jf = new JDBCFile("ma", "");
this.dispose();
JFrame jframe = new YarnSystemFrame(jf);
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = jframe.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
jframe.setLocation((screenSize.width -
frameSize.width) / 2,
(screenSize.height -
frameSize.height) / 2
);
jframe.setVisible(true);
}
}
else
{
JOptionPane.showMessageDialog(this, "密码错误", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
else{
JOptionPane.showMessageDialog(this, "用户名或密码错误", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "用户名或密码错误", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
else
JOptionPane.showMessageDialog(this, "用户名和密码不能空", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
class LogOn_jButton1_actionAdapter implements ActionListener {
private LogOn adaptee;
LogOn_jButton1_actionAdapter(LogOn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -