📄 adminframe.java
字号:
package bank;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import javax.swing.JPasswordField;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import javax.swing.ImageIcon;
//管理员界面类
public class AdminFrame extends JFrame
{
public AdminFrame() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
}
private void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel1.setForeground(Color.blue);
jLabel1.setBorder(null);
jLabel1.setText("管理员号:");
///刷新屏幕////
this.setTitle("登陆系统");
this.setSize(new Dimension(410,320));
this.getContentPane().setLayout(xYLayout1);
jButton2.addActionListener(new AdminFrame_jButton2_actionAdapter(this));
this.getContentPane().setBackground(new Color(234, 168, 255));
this.setForeground(SystemColor.control);
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton2.setText("重置");
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton1.setText("确定");
jButton1.addActionListener(new AdminFrame_jButton1_actionAdapter(this));
jLabel2.setForeground(SystemColor.activeCaption);
this.getContentPane().add(jLabel1, new XYConstraints(37, 82, 81, 34));
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel2.setText("密码:");
jLabel2.setVisible(true);
this.getContentPane().add(jTextField1, new XYConstraints(140, 80, 119, 32));
this.getContentPane().add(jPasswordField1,
new XYConstraints(139, 143, 120, 34));
this.getContentPane().add(jLabel2, new XYConstraints(40, 144, 69, 29));
this.getContentPane().add(jButton1, new XYConstraints(86, 218, 93, 27));
this.getContentPane().add(jButton2, new XYConstraints(228, 217, 97, 28));
}
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton(new ImageIcon("d.gif"));
JButton jButton2 = new JButton(new ImageIcon("f.gif"));
void login_true()
{
login = true;
}
void login_false()
{
login = false;
}
void SetCardID(int ID)
{
admin_ID = ID;
}
private int admin_ID;
private boolean login = false;
private Connection con;
private Statement stmt;
JPasswordField jPasswordField1 = new JPasswordField();
public void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jPasswordField1.setText("");
}
public void jButton1_actionPerformed(ActionEvent e)
{
if(e.getSource()==jButton1)
{
try{
con = bankconnect.getconn();
if(jTextField1.getText().trim()!= null)
{
stmt = con.createStatement();
String loginQuery ="";
String passwordtemp ="";
for(int i=0;i<jPasswordField1.getPassword().length;i++)
{
passwordtemp += jPasswordField1.getPassword()[i];
}
loginQuery = "select * from admin where admin_ID = " +
Integer.parseInt(jTextField1.getText().trim()) +
" and admin_pswd = "+passwordtemp;
ResultSet rs = stmt.executeQuery(loginQuery);
if (rs.next())
{
rs.close();
con.close();
this.hide();
AdminChooseFrame adcf=new AdminChooseFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//getDefaultToolkit()是获取默认工具包,获取该系统屏幕的大小
Dimension frameSize = adcf.getSize(); //获取该窗体的大小
adcf.setState(adcf.NORMAL);//设置窗体正常状态,不是最大化
adcf.setLocation( (screenSize.width - frameSize.width)/2 ,(screenSize.height - frameSize.height)/2 );//重设置该窗体的位置,放于系统中央
adcf.show();
return;
}
else
{
// Frame1.login_false();
jTextField1.setText("卡号或者密码错误。");
}
}
}
catch(SQLException ex)
{
System.out.println("数据库连接错误!"+ex.toString());
}
}
}
}
class AdminFrame_jButton1_actionAdapter
implements ActionListener {
private AdminFrame adaptee;
AdminFrame_jButton1_actionAdapter(AdminFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class AdminFrame_jButton2_actionAdapter
implements ActionListener {
private AdminFrame adaptee;
AdminFrame_jButton2_actionAdapter(AdminFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -