?? login.java
字號:
package coursedesign;
import java.awt.*;
import javax.swing.JOptionPane;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.BorderFactory;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.Dimension;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Login
extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JTextField Name_Text = new JTextField();
JLabel jLabel2 = new JLabel();
JPasswordField Password_Text = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel3 = new JLabel();
public Login() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(400, 300));
setTitle("登陸");
jPanel1.setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleGradient"));
jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
jPanel1.setLayout(xYLayout2);
jLabel1.setText(
"用戶名: " +
" " +
" ");
jLabel2.setText("密 碼:");
jButton1.setText("登陸");
jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
jButton2.setText("退出");
jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
contentPane.setBackground(SystemColor.info);
jPanel1.add(jLabel1, new XYConstraints(114, 20, 74, -1));
jPanel1.add(Password_Text, new XYConstraints(200, 63, 118, -1));
jPanel1.add(Name_Text, new XYConstraints(200, 17, 118, -1));
jPanel1.add(jLabel2, new XYConstraints(112, 54, 56, 33));
jPanel1.add(jButton2, new XYConstraints(239, 110, -1, -1));
jPanel1.add(jButton1, new XYConstraints(113, 110, -1, -1));
contentPane.add(jLabel3, new XYConstraints(0, 0, 402, 304));
contentPane.add(jPanel1, new XYConstraints( -3, 47, 404, 180));
Icon f =new ImageIcon("11.JPJ");
jLabel3.setIcon(f);
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void jButton1_actionPerformed(ActionEvent e) {
String username=Name_Text.getText().trim();
String password=Password_Text.getText().trim();
if(username.equals("")||password.equals(""))
{
JOptionPane.showMessageDialog(null,"用戶名或密碼不能為空!");
}else{
try {
//建立數(shù)據(jù)庫連接對象
Jdbcconn conn = new Jdbcconn();
//連接數(shù)據(jù)庫
conn.OpenConn("student", "sa", "zjxy2006");
String strSQL = "select * from stu where id='" + username + "'";
try {
//得到記錄;
ResultSet rs = conn.getResults(strSQL);
rs.first();
String PassWord = rs.getString("password").toString().trim(); //得到數(shù)據(jù)庫中對應(yīng)用戶名的密碼
int right = rs.getInt("rightlimit");
rs.close();
if (password.equals(PassWord)) {
JOptionPane.showMessageDialog(null, "成功登陸!");
dispose();
chaxunchengji cxcj = new chaxunchengji();
cxcj.username = username;
Main_Frame mainFrame = new Main_Frame();
mainFrame.users = username;
mainFrame.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = mainFrame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
mainFrame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
mainFrame.users = username;
switch(right)
{
case 0://學生用戶
mainFrame.jMenuItem4.setVisible(false);
mainFrame.jMenuItem6.setVisible(false);
mainFrame.jMenuItem1.setVisible(false);
mainFrame.jMenuItem3.setVisible(false);
break;
case 1://教師用戶
mainFrame.jMenuItem3.setVisible(false);
mainFrame.jMenuItem6.setVisible(false);
break;
default://管理員用戶
mainFrame.setTitle("學生成績管理系統(tǒng)");
break;
}
}
else {
JOptionPane.showMessageDialog(null, "密碼錯誤,請重輸!");
Password_Text.setText("");
}
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "用戶名或密碼錯誤1!");
Name_Text.setText("");
Password_Text.setText("");
}
conn.closeConn(); //關(guān)閉數(shù)據(jù)庫連接
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "用戶名或密碼錯誤2!!");
System.out.print(ex.getMessage());
}//first try catch
} //second try catch
}//end else
}//end method
class Login_jButton1_actionAdapter
implements ActionListener {
private Login adaptee;
Login_jButton1_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Login_jButton2_actionAdapter
implements ActionListener {
private Login adaptee;
Login_jButton2_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -