[java]代码库
package com.lzy;
/*
* 登录窗口
*/
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import com.lzy.adm.AdminView;
import com.lzy.sql.GetSQL;
import com.lzy.stuExam.Student;
public class LoginView extends JFrame implements ActionListener {
JLabel jlb1,jlb2,jlb3;
JTextField jtf;
JPasswordField jpf;
JButton jb1,jb2;
JRadioButton jrb1,jrb2;
ButtonGroup bg;
JPanel jp1,jp2,jp3,jp4;
Color color=new Color(100, 155,225);
LoginView(){
jlb1=new JLabel("用户名:");
jlb2=new JLabel("密 码:");
jlb3=new JLabel("权 限:");
jtf=new JTextField(10);
jpf=new JPasswordField(10);
jb1=new JButton("登录");
jb2=new JButton("退出");
//注册监听
jb1.addActionListener(this);
jb2.addActionListener(this);
jrb1=new JRadioButton("学生",true);
jrb2=new JRadioButton("管理员");
//透明按钮
jrb1.setContentAreaFilled(false);
jrb2.setContentAreaFilled(false);
//按钮组
bg=new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
//注册监听
jrb1.addActionListener(this);
jrb2.addActionListener(this);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp1.add(jlb1);
jp1.add(jtf);
jp2.add(jlb2);
jp2.add(jpf);
jp3.add(jlb3);
jp3.add(jrb1);
jp3.add(jrb2);
jp4.add(jb1);
jp4.add(jb2);
jp1.setBackground(color);
jp2.setBackground(color);
jp3.setBackground(color);
jp4.setBackground(color);
this.setLayout(new GridLayout(4,1));
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.setTitle("在线考试系统");
this.setSize(300,250);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand()=="退出"){
System.exit(0);
}else {
if(e.getActionCommand()=="登录"){
if(!(jtf.getText().isEmpty()) && !(jpf.getText().isEmpty())){
//连接数据库
GetSQL.connectSQL();
//权限选择
if(jrb1.isSelected()){
//查找用户
GetSQL.stu(jtf.getText());
if(GetSQL.pwd==null){
this.clear();
}else {
if(GetSQL.pwd.equals(jpf.getText().trim())){
JOptionPane.showMessageDialog(null, "登录成功!");
this.clear();
this.dispose();
new Student();
}else {
JOptionPane.showMessageDialog(null, "密码不正确,请重新输入!");
this.clear();
}
}
}
//权限选择
if(jrb2.isSelected()){
//查找用户
GetSQL.adm(jtf.getText());
if(GetSQL.pwd==null){
this.clear();
}else {
if(GetSQL.pwd.equals(jpf.getText().trim())){
JOptionPane.showMessageDialog(null, "登录成功!");
this.clear();
this.dispose();
new AdminView();
}else {
JOptionPane.showMessageDialog(null, "密码不正确,请重新输入!");
this.clear();
}
}
}
}else {
JOptionPane.showMessageDialog(null, "请输入所有信息");
this.clear();
}
}
}
}
//清空
private void clear(){
jtf.setText("");
jpf.setText("");
}
// public static void main (String args[]){
// new Login();
// }
}
package com.lzy;
public class Main {
public static void main (String args[]){
new LoginView();
}
}
初级程序员
by: yebin 发表于:2018-05-04 20:07:49 顶(0) | 踩(0) 回复
1
回复评论