📄 denglu.java~28~
字号:
package MainFrame;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import DataBaseManager.DataBaseManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class DengLu extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel4 = new JLabel();
String z[]={"用户","管理员"};
JComboBox jComboBox1 = new JComboBox(z);
public DengLu() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
jLabel1.setFont(new java.awt.Font("华文彩云", Font.BOLD, 20));
jLabel1.setForeground(Color.green);
jLabel1.setText("登录界面");
jButton1.addActionListener(new DengLu_jButton1_actionAdapter(this));
this.addWindowListener(new DengLu_this_windowAdapter(this));
jButton2.addActionListener(new DengLu_jButton2_actionAdapter(this));
xYLayout1.setWidth(400);
xYLayout1.setHeight(328);
jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel4.setText("权限");
this.getContentPane().setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleBackground"));
this.getContentPane().add(jLabel1, new XYConstraints(148, 29, 191, 36));
jButton2.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jButton2.setText("取消");
jButton1.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jButton1.setText("确定");
jPasswordField1.setToolTipText("");
jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel3.setText("密码");
this.getContentPane().add(jPasswordField1,
new XYConstraints(142, 150, 160, 40));
this.getContentPane().add(jTextField1,
new XYConstraints(142, 80, 160, 40));
this.getContentPane().add(jLabel3, new XYConstraints(56, 145, 74, 43));
this.getContentPane().add(jLabel2, new XYConstraints(56, 84, 81, 35));
this.getContentPane().add(jComboBox1,
new XYConstraints(142, 209, 159, 42));
this.getContentPane().add(jButton1, new XYConstraints(74, 267, 80, 40));
this.getContentPane().add(jButton2, new XYConstraints(250, 267, 80, 40));
this.getContentPane().add(jLabel4, new XYConstraints(56, 206, 68, 38));
jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel2.setText("帐号");
}
public static void main(String[] args) {
DengLu d = new DengLu();
d.setTitle("登录界面");
d.setBounds(200,200,400,400);
d.setVisible(true);
}
public void jButton1_actionPerformed(ActionEvent e) {
try {Connection con;
Statement stmt;
ResultSet rs,rs1;
String q=(String)jComboBox1.getSelectedItem();
String a= jTextField1.getText();
int w=Integer.parseInt(a);
char b[]=jPasswordField1.getPassword();
String c=new String(b);
if(a.equals("")){
JOptionPane.showMessageDialog(null,"沒有輸入用戶ID!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
else if(c.equals("")){
JOptionPane.showMessageDialog(null,"沒有輸入密碼!","輸入錯誤",JOptionPane.ERROR_MESSAGE); }
else{ if(q.equals("用户")){ DataBaseManager dbm=new DataBaseManager();
dbm.connect();
String strSQL="select * from userTable where userid='"+ w+"'and userpassword='"
+c+"'";
rs=dbm.getResult(strSQL);
if(rs.next()){
this.dispose();
JOptionPane.showMessageDialog(null,"登录成功");
ZhuJieMian z=new ZhuJieMian();
z.setBounds(200,200,400,400);
z.setVisible(true);}
// else
// { JOptionPane.showMessageDialog(null,"用户名不存在或密码错误!");}
}
if(q.equals("管理员")){ DataBaseManager dbm1=new DataBaseManager();
dbm1.connect();
String str="select * from userTable where userid='"+ w+"'and userpassword='"
+c+"'";
rs1=dbm1.getResult(str);
if(rs1.next()){
this.dispose();
JOptionPane.showMessageDialog(null,"登录成功");
Update u=new Update();
u.setBounds(200,200,500,500);
u.setVisible(true);
} else
{ JOptionPane.showMessageDialog(null,"用户名不存在或密码错误!");}
}
// else
//{ JOptionPane.showMessageDialog(null,"用户名不存在或密码错误!");
jTextField1.setText("");
jPasswordField1.setText("");
}//catch (Exception ex) {
// System.out.println("数据库连接失败");
// }finally{
// dbm.disconnect();
//}//}
} catch(Exception ex){
JOptionPane.showConfirmDialog(null,"請您取卡");
} }
public void this_windowClosing(WindowEvent e) {
System.exit(0);
}
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
HuanYing h=new HuanYing();
h.setBounds(200,200,400,400);
h.setVisible(true);
}
}
class DengLu_this_windowAdapter extends WindowAdapter {
private DengLu adaptee;
DengLu_this_windowAdapter(DengLu adaptee) {
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e) {
adaptee.this_windowClosing(e);
}
}
class DengLu_jButton2_actionAdapter implements ActionListener {
private DengLu adaptee;
DengLu_jButton2_actionAdapter(DengLu adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class DengLu_jButton1_actionAdapter implements ActionListener {
private DengLu adaptee;
DengLu_jButton1_actionAdapter(DengLu adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -