st2);
if (isSuccess) {
new StudentInformationUI(); dispose();
JOptionPane.showMessageDialog(null, \用户名
} else
密码错误\, \提示信息\, JOptionPane.INFORMATION_MESSAGE); }
}
class ExitActionListener implements ActionListener { }
public static void main(String[] args) { }
new StudentLoginUI();
public void actionPerformed(ActionEvent e) { }
System.exit(0); }
执行截图如下:
(3)StudentInformationUI类:此类为学生信息界面,此类
中有一个标签和一个表格。标签中从StudentLoginUI类中获取学生登录时使用的用户名,显示在标签中以表示以下是某某同学的信息。表格中为此学生的信息。调用InformationDao类中的queryInformation1(),将得到的
ArrayList对象lis放入Vector对象中,形成表格。 StudentInformationUI类源代码:
package ui;
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel; import Model.Information; import Dao.InformationDao;
public class StudentInformationUI extends JFrame{
String aa=StudentLoginUI.st1; JLabel selectionLabel; JPanel topPanel; Container container; JTable table;
JScrollPane bookScrollPane; JPanel bottomPanel;
public StudentInformationUI(){
container = this.getContentPane();
selectionLabel = new JLabel(aa+\同学通讯录信息如下\); topPanel = new JPanel(); topPanel.setLayout(new
topPanel.add(selectionLabel);
this.add(BorderLayout.NORTH, topPanel); table = new JTable();
bookScrollPane = new JScrollPane(table); this.add(BorderLayout.CENTER, bookScrollPane); bottomPanel = new JPanel();
this.add(BorderLayout.SOUTH, bottomPanel); this.setTitle(\学生信息\); this.setSize(600, 450); this.setVisible(true);
InformationDao oneInformation=new
FlowLayout(FlowLayout.CENTER));
InformationDao();
}
}
ArrayList lis =
Vector
head.add(\系别\);
Vector
DefaultTableModel model = new table.setModel(model); repaint();
Vector row = new Vector();
Information oneInformation1 = (Information) row.add(oneInformation1.getSnum()); row.add(oneInformation1.getSname()); row.add(oneInformation1.getPhonumber()); row.add(oneInformation1.getSex()); row.add(oneInformation1.getDept()); content.add(row);
oneInformation.queryInformation1(aa);
lis.get(i);
DefaultTableModel(content, head);
执行截图如下:
(6)TeacherLoginUI类:此类为教师登陆界面,在这个界面上有两个文本框,分别输入教师姓名和登录密码,还有两个按钮,登陆和退出。输入后,从两个文本框中获取用户输入的内容,点击“登陆”按钮时,调用TeacherDao类中的queryTeacher()方法验证是否存在该用户。若存在创建TeacherMainUI类的对象,即打开教师主界面,若不存在,则提示密码错误。
TeacherLoginUI类源代码:
package ui;
import java.awt.*; import java.awt.event.*; import javax.swing.*; import Dao.TeacherDao;
public class TeacherLoginUI extends JFrame {
JLabel l1, l2; JTextField t1; JPasswordField t2; JButton bt1, bt2; Container cp;
public TeacherLoginUI(){
l1 = new JLabel(\教师姓名\); l2 = new JLabel(\密码\); t1 = new JTextField(12); t2 = new JPasswordField(12); bt1 = new JButton(\登录\); bt2 = new JButton(\退出\); JPanel p1 = new JPanel(); p1.setLayout(null);
l1.setBounds(150, 150, 80, 40); p1.add(l1);
t1.setBounds(250, 150, 80, 30); p1.add(t1);
l2.setBounds(150, 190, 80, 40); p1.add(l2);
t2.setBounds(250, 190, 80, 30); p1.add(t2);
bt1.setBounds(150, 230, 80, 30);
p1.add(bt1);
bt2.setBounds(250, 230, 80, 30); p1.add(bt2);
bt1.addActionListener(new
LoginActionListener());//注册事件 bt2.addActionListener(new ExitActionListener());//注册事件 cp = getContentPane();
}
class LoginActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String st1 = t1.getText(); String st2 = t2.getText(); TeacherDao oneTeacherDao = new TeacherDao(); boolean isSuccess = if (isSuccess) {
new TeacherMainUI(); dispose();
JOptionPane.showMessageDialog(null, \用户名
this.setBounds(200, 200, p1.getHeight(), cp.add(p1);
this.setTitle(\教师登录界面\); this.setSize(400, 400); this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { }
System.exit(0);
p1.getHeight());
});
oneTeacherDao.Teacherlogin(st1, st2);
} else
密码错误\, \提示信息\,
JOptionPane.INFORMATION_MESSAGE);
}
}