import javax.swing.*;
import java.awt.*;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.border.*;
class Imagecanvas extends Canvas{
Toolkit tool;
Image myimage;
Imagecanvas(){
setSize(326,47);
tool=getToolkit();
myimage=tool.getImage("qq1.jpg");
}
public void paint(Graphics g){
g.drawImage(myimage,0,0,326,47,this);
}
}
class Login extends JFrame{
JButton jButton1=new JButton("登录");
JButton jButton2=new JButton("取消");
JButton jButton3=new JButton("查杀木马↓");
JLabel jLabel2=new JLabel("QQ账号:");
JLabel jLabel3=new JLabel("QQ密码:");
JLabel jLabel4=new JLabel("申请号码");
JTextField jTextField2=new JTextField (11);
JPasswordField jPasswordField1=new JPasswordField(11);
JCheckBox check1=new JCheckBox("自动登陆");
JCheckBox check2=new JCheckBox("隐身登陆");
int r=240,g=250,b=255;
Color myColor=new Color(r,g,b);
int r1=210,g1=235,b1=255;
Color myColor1=new Color(r1,g1,b1);
String user,password;
Connection conn;
Statement stmt;
static String Loginuser,Loginpassword;
static boolean Loginc,Logink;
JPanel jpanel1,jpanel2,jpanel3;
public Login()
{
super("QQ用户登录");
//this.setBounds(250,250,300,200);
setResizable(true);
try{jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit()throws Exception
{
Frame fra=new Frame("QQ用户登录");
setBounds(350, 300, 330,240);
Container c=getContentPane();
FlowLayout layout=new FlowLayout(FlowLayout.CENTER);
JPanel jpanel1=new JPanel();
JPanel jpanel2=new JPanel();
JPanel jpanel21=new JPanel();
JPanel jpanel22=new JPanel();
JPanel jpanel3=new JPanel();
Imagecanvas canvas1=new Imagecanvas();
jpanel1.add(canvas1);
jpanel1.setSize(326,47);
//jTextField2.setFont(new Font("",10,25));
//jPasswordField1.setFont(new Font("",10,25));
// jpanel2.add(new JLabel(" "));
jpanel21.add(jLabel2);
jpanel21.add(jTextField2);
jpanel21.add(jLabel4);
//jpanel2.add(new JLabel(" "));
jpanel22.add(jLabel3);
jpanel22.add(jPasswordField1);
jpanel22.add(new JLabel("<html><font color=blue>忘记密码</font><html>"));
jpanel2.add(jpanel21);
jpanel2.add(jpanel22);
jpanel2.add(check1);
jpanel2.add(check2);
Border border =BorderFactory.createEtchedBorder();
jpanel2.setBorder(border);
jpanel3.add(jButton3);
jpanel3.add(jButton2);
jpanel3.add(new JLabel(" "));
jpanel3.add(new JLabel(" "));
jpanel3.add(jButton1);
setLayout(new BorderLayout());
add(BorderLayout.NORTH,jpanel1);
add(BorderLayout.CENTER,jpanel2);
add(BorderLayout.SOUTH,jpanel3);
jLabel3.setVerifyInputWhenFocusTarget(true);
jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
jPasswordField1.setVerifyInputWhenFocusTarget(true);
//jButton1.setForeground(Color.blue);
//jLabel2.setForeground(Color.blue);
jLabel4.setForeground(Color.blue);
jpanel1.setBackground(myColor1);
jpanel2.setBackground(myColor);
jpanel21.setBackground(myColor);
jpanel22.setBackground(myColor);
jpanel3.setBackground(myColor1);
check1.setBackground(myColor);
check2.setBackground(myColor);
jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
jTextField2.addActionListener(new Login_jButton1_actionAdapter(this));
//jLabel3.setForeground(Color.blue);
jPasswordField1.addActionListener(new Login_jButton1_actionAdapter(this));
jPasswordField1.addMouseListener(new Login_jPasswordField1_mouseAdapter(this));
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
setBounds(473, 261, 330,240);
validate();
}
void jButton2_actionPerformed(ActionEvent e){
System.exit(0);
}
private static boolean isPasswordCorrect(char[]input){
char[]correctPassword;
correctPassword=Loginpassword.toCharArray();
if(input.length!=correctPassword.length){
return false;
}
for(int i=0;i<input.length;i++){
if(input[i]!=correctPassword[i]){
System.out.print("密码错误!");
return false;
}
}
return true;
}
void jButton1_actionPerformed(ActionEvent e)// 实现查询功能
{
String user=jTextField2.getText();
char[]password=jPasswordField1.getPassword();
try{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
}
Connection conn= DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=database//database.mdb","","");
Statement stmt= conn.createStatement();
ResultSet rs=stmt.executeQuery("select *from 表1");
while(rs.next()){
Loginuser=rs.getString("用户名");
Loginpassword=rs.getString("密码");
}
stmt.close();
conn.close();
}
catch(SQLException ex1){
System.out.print(ex1);
}
if(jTextField2.getText().toLowerCase().equals(Loginuser.toLowerCase())&&
isPasswordCorrect(password)) {
JFrame.setDefaultLookAndFeelDecorated(true);
DataWindow window=new DataWindow();
window.validate();
// JOptionPane.showMessageDialog(this,"正确","进入",
//JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(this,"登录失败",
"警告",
JOptionPane.ERROR_MESSAGE);
}
/* void this_windowClosing(WindowEvent e) {
System.exit(0);
}*/
}
void jPasswordField1_mouseClicked(MouseEvent e) {
}
class Login_jButton1_actionAdapter
implements java.awt.event.ActionListener{
Login adaptee;
Login_jButton1_actionAdapter(Login adaptee)
{
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButton1_actionPerformed(e);
}
}
class Login_jButton2_actionAdapter
implements java.awt.event.ActionListener{
Login adaptee;
Login_jButton2_actionAdapter(Login adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButton2_actionPerformed(e);
}
}
class Login_this_windowAdapter
extends java.awt.event.WindowAdapter{
Login adaptee;
Login_this_windowAdapter(Login adaptee){
this.adaptee=adaptee;
}
/*public void windowClosing(WindowEvent e){
adaptee.this_windowClosing(e);
}*/
}
class Login_jPasswordField1_mouseAdapter
extends java.awt.event.MouseAdapter{
Login adaptee;
Login_jPasswordField1_mouseAdapter(Login adaptee){
this.adaptee=adaptee;
}
public void mouseClicked(MouseEvent e){
adaptee.jPasswordField1_mouseClicked(e);
}
}
public static void main(String args[])
{
new Login();
}
}