实例介绍
随着高校教学资源逐步开发,高校教育资源的应用种类逐步增多。而实验室作为高校基本教育资源之一,与日常教学工作开展、课堂项目实践有着密切联系。由此,如何借助新时期技术,加强高校实验室应用数据信息程序开发,在高校智能化管理程序推广中占有基础性地位。该软件是以Java语言为实现预言。其功能在系统内部有源代码直接完成,操作人员只需输入一些简单的汉字,数字,即可达到自己的目标。
登陆账号:admin 密码:123456
import com.company.Bean.Teacher;
import com.company.Bean.User;
import com.company.DB.DB;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
private JPanel p;
private JLabel lblName,lblPwd,lblRole;
private JTextField txtName;
private JPasswordField txtPwd;
private JButton btnOk,btnCancle;
String[] s = {"学生","教师","管理员"};
private JComboBox comboBox;
public Main(){
super("用户登录界面");
p = new JPanel();
p.setLayout(null);
lblRole=new JLabel("角色:");
comboBox=new JComboBox(s);
lblName = new JLabel("账户:");
lblPwd = new JLabel("密码:");
txtName = new JTextField(20);
txtPwd = new JPasswordField(20);
btnOk = new JButton("登录");
btnCancle = new JButton("取消");
//注册确定按钮的事件处理
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String strName = txtName.getText();
String strPwd = new String(txtPwd.getPassword());
System.out.println("用户名:" strName "\n密码:" strPwd);
});
//注册取消按钮的事件处理
btnCancle.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//清空
txtName.setText("");
txtPwd.setText("");
});
lblRole.setBounds(90,50,60,25);
comboBox.setBounds(130,50,140,25);
lblName.setBounds(90,80,60,25);
txtName.setBounds(130,80,140,25);
lblPwd.setBounds(90,110,60,25);
txtPwd.setBounds(130,110,140,25);
btnOk.setBounds(130,150,60,25);
btnCancle.setBounds(200,150,60,25);
p.add(lblRole);
p.add(comboBox);
p.add(lblName);
p.add(txtName);
p.add(lblPwd);
p.add(txtPwd);
p.add(btnOk);
p.add(btnCancle);
this.add(p);
this.setSize(400,300);
this.setLocation(300,300);
//设置窗体不可改变大小
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String account =txtName.getText().trim();
String password=txtPwd.getText().trim();
String role=null;
if(comboBox.getSelectedItem().equals("管理员")){
role="admin";
}
else if(comboBox.getSelectedItem().equals("学生")) {
role="student";
}
else{
role="teacher";
}
if(role.equals("admin")){
User user=new User(account,password);
if (DB.Login(user)) {
JOptionPane.showMessageDialog(null, "登录成功", "", JOptionPane.PLAIN_MESSAGE);
AdminMain adminMain = new AdminMain();
adminMain.setVisible(true);
Main.this.setVisible(false);
}
else {
JOptionPane.showMessageDialog(null,"账号密码错误", "", JOptionPane.PLAIN_MESSAGE);
}
}
else if (role.equals("student")){
Student student=new Student(account,password);
if(DB.studentLogin(student)){
StudentMain studentMain=new StudentMain();
studentMain.setVisible(true);
Main.this.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功", "", JOptionPane.PLAIN_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null,"账号密码错误", "", JOptionPane.PLAIN_MESSAGE);
}
}
else if (role.equals("teacher")){
Teacher teacher=new Teacher(account,password);
if(DB.teacherLogin(teacher)){
TeacherMain teacherMain=new TeacherMain();
teacherMain.setVisible(true);
Main.this.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功", "", JOptionPane.PLAIN_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null,"账号密码错误", "", JOptionPane.PLAIN_MESSAGE);
}
}
}
});
btnCancle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
}
public static void main(String[] args) {
// write your code here
Main main=new Main();
main.setVisible(true);
}
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论