为什么我的按钮没有反应啊?求救、、、
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Denglu extends JFrame implements
ActionListener,ItemListener //这是登录界面的开始设计
{
JLabel a1,a2,a3,a4;
JButton b1,b2,b3;
JRadioButton c1,c2;
JTextField d1;
JPasswordField e1;
ButtonGroup g1;
JPanel f2;
String s3="";
public Denglu()
{
setTitle("登录窗口");
setSize(500,500);
JPanel f1=(JPanel)getContentPane();
f1.setLayout(new FlowLayout());
a2=new JLabel("用户名: ");
a3=new JLabel("密码: ");
a4=new JLabel();//a4是为验证权限作的定义
a4.setSize(80,30);
a4.setVisible(false);//a4是不可见的
d1=new JTextField(10);
e1=new JPasswordField(10);
e1.setEchoChar('*');
c1=new JRadioButton("管理员");
c2=new JRadioButton("读者");
g1=new ButtonGroup();
g1.add(c1);g1.add(c2);
b1=new JButton("登录");
b2=new JButton("注册");
b3=new JButton("退出");
f1.add(a4); //下面加了许多的 new JLabel(" ")也是为了布局
f1.add(new JLabel(" "));
f1.add(a2);f1.add(d1);f1.add(new JLabel(" "));
f1.add(new JLabel(" "));f1.add(a3);f1.add(e1);f1.add(new JLabel(" "));
f1.add(new JLabel(" "));f1.add(c1);f1.add(c2);f1.add(new JLabel(" "));
f1.add(b1);f1.add(new JLabel(" "));f1.add(b2);f1.add(new JLabel(" "));f1.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
c1.addItemListener(this);
c2.addItemListener(this);
}
public void itemStateChanged(ItemEvent i1)
{
Connection con; //为建立连接数据库用的
Statement stmt; //为作查询用的
ResultSet rs1; //为反应结果用的
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException i3)
{ }
if(c1.isSelected()==true) //此时c1是管理员
{
s3=c1.getText(); //这里是s3获取单选按钮里面的内容
try{
con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=shuji.mdb");
stmt=con.createStatement();
String condition=("select * from student where 权限种别='"+s3+"'"); //查询用户表里的权限种别是否有管理员
rs1=stmt.executeQuery(condition);
if(rs1.next())
{
a4.setText(s3);
}
con.close();
}catch(SQLException i4) {}
}
if(c2.isSelected()==true) //此时c2是读者
{
s3=c2.getText();//这里是s3获取单选按钮里面的内容
try
{
con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=shuji.mdb");
stmt=con.createStatement();
String condition=("select * from student where 权限种别 ='"+s3+"'");//验证数据库里是否有读者
rs1=stmt.executeQuery(condition);
if(rs1.next())
{
a4.setText(s3);
}
con.close();
}catch(SQLException i4) {}
}
}
public void actionPerformed(ActionEvent i2)
{ Connection con;
Statement stmt;
ResultSet rs1;
String s1="",s2="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException i5)
{ }
if(i2.getSource()==b1)//登录按钮
{
s1=d1.getText();//获取用户输入的用户名内容
s2=new String(e1.getPassword());//获取用户输入的密码
s3=a4.getText();//获取用户选择的权限
try{
con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=shuji.mdb");
stmt=con.createStatement();
String condition=("select * from student where 用户名='"+s1+"' and密码='"+s2+"' and权限种别='"+s3+"'");//获取的信息与数据库中的用户表相核对是否正确
rs1=stmt.executeQuery(condition);
if(rs1.next())
{
JOptionPane.showMessageDialog(null,"登录成功 ");
if(s1.equals("admin")==true) //如果用户名是admin(数据库里的管理员只有admin ),就进入管理员的界面 ,因为管理员和用户的权限不同
{
Admin x6=new Admin(); //调用Admin类 ***********************************
x6.setVisible(true);
//setVisible(false); //将当前登录窗体设置为不可见
}
else
{ //如果验证用户名不是admin ,就进入读者界面
Reader x2=new Reader(); //调用读者的类 **********************************
x2.setVisible(true); //设置读者的窗体为可见
}
//setVisible(false); //设置当前的窗体不可见
}
else{
JOptionPane.showMessageDialog(null, "用户名或密码或权限种别错误!!!");} //如果上面的验证信息有一项与数据库里的不符就提示登录失败
con.close();
}catch(SQLException i6) {}
}
if(i2.getSource()==b2){ //还是调用类(注册类)
Zhuce x2=new Zhuce();
x2.setVisible(true);
//setVisible(false);
}
if(i2.getSource()==b3)//退出
{
JOptionPane.showMessageDialog(null,"谢谢使用!!");
System.exit(0);
}
}