?? denglu.java~29~
字號:
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 + -