}
class ExitActionListener implements ActionListener { }
public static void main(String[] args) { }
new TeacherLoginUI();
public void actionPerformed(ActionEvent e) { }
System.exit(0);
执行截图如下:
(7)TeacherMainUI类:此类为教师主界面类,在此界面上有一个菜单栏,三个菜单:文件,查询,修改。其中“文件”菜单中有“退出”菜单项,点击时跳出对话框问是否真的退出,若点击是,窗口关闭,若点击否,回复原界面。“查询”菜单中有“学生基本信息”菜单项:当点击“学生基本信息”时,通过注册事件,创建InformationQueryUI类的对象,即打开查询学生基本信息的窗口,修改菜单中有“增加新生信息”“删除毕业生信息”“更新”三个菜单项,当点击“增加新生信息”时,通过注册事件,创建InformationAddUI类的对象,即打开添加学生基本信息的窗口,当点击“删除毕业生信息”时,通过注册事件,创建InformationDeleteUI类的对象,即打开删除学生基本信息的窗口。 TeacherMainUI类源代码:
package ui;
import java.awt.*; import java.awt.event.*;
import javax.swing.*;
public class TeacherMainUI extends JFrame{ Container ctp; TeacherMainUI(){
}
public void buildMainMenu(JMenuBar menuBar){
JMenu fileMenu=new JMenu(\文件\);
JMenuItem exitMenuItem=new JMenuItem(\退出\); exitMenuItem.addActionListener(new ctp = this.getContentPane();
this.setTitle(\欢迎进入学生通讯录管理系统!\); ctp.setLayout(new BorderLayout()); JMenuBar menuBar = new JMenuBar(); buildMainMenu(menuBar); this.setJMenuBar(menuBar);
this.setBounds(100, 100, 400, 300); this.setVisible(true);
ExitActionListener());//注册事件 fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
JMenu queryMenu=new JMenu(\查询\);
JMenuItem queryMenuItem=new JMenuItem(\学生基本信息queryMenuItem.addActionListener(new
\);
QueryActionListener());//注册事件 queryMenu.add(queryMenuItem);
menuBar.add(queryMenu);
JMenu changeMenu=new JMenu(\修改\);
JMenuItem addMenuItem=new JMenuItem(\增加信息\); JMenuItem deleteMenuItem=new JMenuItem(\删除信息\); JMenuItem updateMenuItem=new JMenuItem(\更新信息\); addMenuItem.addActionListener(new
AddActionListener());//注册事件 deleteMenuItem.addActionListener(new DeleteActionListener());//注册事件 updateMenuItem.addActionListener(new UpdateActionListener());//注册事件
}
changeMenu.add(addMenuItem); changeMenu.add(deleteMenuItem); changeMenu.add(updateMenuItem); menuBar.add(changeMenu);
class ExitActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(null,
\真的要退出吗?\, \提示信息\,
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
}
class QueryActionListener implements ActionListener{ }
class AddActionListener implements ActionListener{ }
class DeleteActionListener implements ActionListener{ }
public static void main(String[] args) { }
}执行截图如下:
new TeacherMainUI();
public void actionPerformed(ActionEvent e){
new InformationDeleteUI();
public void actionPerformed(ActionEvent e){
new InformationAddUI();
public void actionPerformed(ActionEvent e){ }
new InformationQueryUI(); }
}
null);
if (result == 0)
System.exit(0); else if (result == 1) {
}
}
(8)InformationQueryUI类:此类为学生信息查询界面类,在此界面有一个标签,一个文本框,三个按钮。在文本框中输入要查询信息的学生姓名,单击“查询该生信息”按钮时,通过注册事件,在内部类的方法里,获取从文本框中获取的学生姓名信息,并把此信息作为实参传给InformationDao类的queryInformation()方法,得到查询结构。同样单击“浏览学生信息”显示数据库中已有学生的信息。再把查询结构通过Vector对象放入ArrayList类的对象lis中,从而使检索结果显示在表格中。 InformationQueryUI类源代码:
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 ui.InformationAddUI.CloseListener; import Model.Information; import Dao.InformationDao;
public class InformationQueryUI extends JFrame{
JLabel selectionLabel; JPanel topPanel; JButton
JTextField keywordText; Container container; String fieldSelected; int selectedSnum; JTable table;
JScrollPane bookScrollPane;
retrievalButton1,retrievalButton2,retrievalButton3;
JPanel bottomPanel;
public InformationQueryUI(){
container = this.getContentPane(); selectionLabel = new JLabel(\学生姓名\); keywordText = new JTextField(\, 20);
retrievalButton1 = new JButton(\查询该生信息\); retrievalButton2 = new JButton(\浏览学生信息\); retrievalButton3 = new JButton(\返回\); topPanel = new JPanel(); topPanel.setLayout(new
keywordText.setSize(topPanel.getWidth() / 2, topPanel.add(selectionLabel); topPanel.add(keywordText); topPanel.add(retrievalButton1); topPanel.add(retrievalButton2); topPanel.add(retrievalButton3);
this.add(BorderLayout.NORTH, topPanel); retrievalButton1.addActionListener(new
FlowLayout(FlowLayout.LEFT)); topPanel.getWidth());
RetrievalActionListener());//给检索按钮注册事件 retrievalButton2.addActionListener(new RetrievalActionListener());
}
class RetrievalActionListener implements
public void actionPerformed(ActionEvent arg0) { retrievalButton3.addActionListener(new 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);
CloseListener());
ActionListener{