想实现不同身份跳转,但只能跳转管理员,求高手在代码上修改,方便的话加一下注释,谢谢
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Login extends WindowAdapter implements ActionListener
{
JLabel imageLabel;
Frame f=new Frame("单机版考试系统");
Label l1=new Label("单机版考试系统");
Label l2=new Label("姓 名:");
TextField t2=new TextField();
Label l3=new Label("密 码:");
JPasswordField t3=new JPasswordField();
Label l4=new Label("考试地点:");
String items1[]={"请选择考试地点","电子学院","商贸学院","化工学院"};
JComboBox jcb1 = new JComboBox(items1);
Label ks=new Label("身份选择:");
String items[]={"学生","管理员"};
JComboBox jcb = new JComboBox(items);
Button b1=new Button("登录");
Button b2=new Button("重置");
public Login()
{
ImageIcon image=new ImageIcon("images/24.jpg");
imageLabel = new JLabel(image);
f.setBounds(400,200,340,350);
f.setLayout(null);
l1.setFont(new Font("隶书",Font.BOLD,30));
l1.setForeground(Color.ORANGE);
l1.setBounds(60,35,250,50);
l2.setBounds(50,130,60,20);
t2.setBounds(130,130,150,20);
l3.setBounds(50,160,60,20);
t3.setBounds(130,160,150,20);
ks.setBounds(50,190,60,20);
jcb.setBounds(130,190,150,20);
l4.setBounds(50,220,60,20);
jcb1.setBounds(130,220,150,20);
b1.setBounds(60,300,100,20);
b2.setBounds(200,300,100,20);
imageLabel.setBounds(0, 0,360,350);
f.addWindowListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
jcb.addActionListener(this);
jcb1.addActionListener(this);
f.add(l1);
f.add(l2);
f.add(t2);
f.add(l3);
f.add(t3);
f.add(ks);
f.add(jcb);
f.add(l4);
f.add(jcb1);
f.add(b1);
f.add(b2);
f.add(imageLabel);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b2)
{
t2.setText("");
t3.setText("");
}
if (e.getSource() == b1)
{
String zkzh = t2.getText();
String xm = t3.getText(); //姓名
String dlsf =(String)jcb.getSelectedItem();
String ksdd =(String)jcb1.getSelectedItem();
new SQL();
Statement st;//向数据库发送sql语句
try
{
st=SQL.conn.createStatement();
String s="select * from Login where 姓名='"+zkzh+"' and 密码='"+xm+"' and 考试地点='"+ksdd+"' and 登录身份='"+dlsf+"' ";
ResultSet rs=st.executeQuery(s);
if(rs.next())
{
System.out.println(dlsf);
//if(dlsf==1)
JOptionPane.showMessageDialog(null,"欢迎管理员进入考试系统!");
new Administratormenu();
f.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"仔细一点哦,密码错了");
t2.setText("");
t3.setText("");
}
}
catch(Exception e3)
{
JOptionPane.showMessageDialog(null,"登录查询数据库出现异常!");
}
}
}
public void windowClosing(WindowEvent e)
{
((Frame) e.getComponent()).dispose();
System.exit(0);
}
public static void main(String args[])
{
new Login();
}
} |
|