/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Demo;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
/**
*
* @author Administrator
*/
public class Login extends JFrame implements ActionListener{
JPanel pnlLogin;
JLabel lblUserName,lblPassword,P;
JButton btnLogin,btnExit;
JTextField txtUserName,txtlbldl;
JPasswordField pwdPassword;
Dimension dsSize;
Toolkit DefaultToolkit();
public Login(){
super("系统名");
pnlLogin=new JPanel();
ContentPane().add(pnlLogin);
pnlLogin.setLayout(null);
lblUserName=new JLabel("用户名(U):");
lblPassword=new JLabel("密码:");
txtUserName=new JTextField(20);
java的jdbc连接数据库 pwdPassword=new JPasswordField(20);
btnLogin=new JButton("登录(L)");
btnLogin.setMnemonic('L');
btnExit=new JButton("退出(X)");
btnExit.setToolTipText("退出系统");
btnExit.setMnemonic('X');
btnLogin.addActionListener(this);
btnExit.addActionListener(this);
Icon logol=new ImageIcon("图片1");
P=new JLabel(logol);
P.setBounds(0,0,315,120);
pnlLogin.add(P);
pnlLogin.setBackground(Color.blue);
lblUserName.setBounds(10,125,90,25);
txtUserName.setBounds(120,125,180,25);
lblPassword.setBounds(10,155,90,25);
pwdPassword.setBounds(120,155,180,25);
btnLogin.setBounds(20,185,80,25);
btnExit.setBounds(220,185,80,25);
lblUserName.setForeground(Color.BLACK);
lblUserName.setBackground(Color.WHITE);
lblPassword.setForeground(Color.BLACK);
lblPassword.setBackground(Color.WHITE);
pnlLogin.add(lblUserName);
pnlLogin.add(txtUserName);
pnlLogin.add(lblPassword);
pnlLogin.add(pwdPassword);
pnlLogin.add(btnLogin);
pnlLogin.add(btnExit);
setResizable(false);
setSize(315,245);
setVisible(true);
ScreenSize();
setLocation(dsSize.Width()/2,dsSize.Height()/2);
Image Image("图片2");
setIconImage(img);
}
@Override
public void actionPerformed(ActionEvent ae){
Source()==btnLogin)
{
String jusername =Text().trim();
char[] s = Password();
String jpassword = new String(s);
if (jusername.equals("") || jpassword.equals(""))
{
JOptionPane.showMessageDialog(this, "对不起,请输入用户名或密码.", "错误!",JOptionPane.ERROR_MESSAGE);
}
else
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
);
//System.out.println("加载驱动程序成功");
}
catch(Exception e)
{
System.out.println("无法加载驱动程序");
}
try{
Connection conn = Connection("jdbc:odbc: **", "sa", " ");
Statement stmt = ateStatement();
ResultSet rs = uteQuery( "select Sno,shenfen from Student where Sno='"+jusername+"'");
if (rs.next())
{
if (rs.getString("shenfen").equals(jpassword))
{
JOptionPane.showMessageDialog(null, "登陆成功");
new zhuProgram();
super.setVisible(false);
}
else {
JOptionPane.showMessageDialog(this, "对不起,密码错误,请重新输入","登陆失败", JOptionPane.ERROR_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(this, "用户名不存在,请重新输入", "错误!",JOptionPane.ERROR_MESSAGE);
}
rs.close();
stmt.close();
}
catch(SQLException e)
{
System.out.println("SQL异常");
}
}
}
Source()==btnExit)
it(0);
}
public static void main(String args[]){
Login d5_3 = new Login();
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论