📄 teacherframe.java
字号:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;;
/**
a student frame with menus
public class TeacherFrame
{
public static void main(String[] args)
{
TeachersFrame myFrame = new TeachersFrame();
myFrame.setVisible(true);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
*/
public class TeacherFrame extends JFrame
{
public TeacherFrame()
{
setTitle("学生选课管理系统(教师)");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setLocation(350, 200);
setResizable(false);
//创建三个菜单
JMenu systemMenu = new JMenu("系统维护");
systemMenu.add(new TeacherMenuAction("修改密码", new ImageIcon("01.gif")));
systemMenu.add(new
AbstractAction("退出系统", new ImageIcon("02.gif"))
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
JMenu functionMenu = new JMenu("功能选项");
functionMenu.add(new TeacherMenuAction("选课名单"));
functionMenu.add(new TeacherMenuAction("成绩管理"));
functionMenu.add(new TeacherMenuAction("查询统计"));
functionMenu.add(new TeacherMenuAction("个人信息"));
JMenu helpMenu = new JMenu("帮助");
helpMenu.add(new
AbstractAction("说明")
{
public void actionPerformed(ActionEvent e)
{
String s = " 本系统是用JAVA语言编写的,可以在\n"
+"任何安装了相应的JAVA虚拟机的系统使用。\n";
JOptionPane.showMessageDialog(TeacherFrame.this, s, "使用说明", JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("01.gif"));
}
});
helpMenu.add(new
AbstractAction("关于")
{
public void actionPerformed(ActionEvent e)
{
String s = " 作者:李常友\n指导老师:龙毅宏";
JOptionPane.showMessageDialog(TeacherFrame.this, s, "作品信息", JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("02.gif"));
}
});
//创建菜单栏,并把菜单添加到菜单栏中
JMenuBar teacherMenuBar = new JMenuBar();
teacherMenuBar.add(systemMenu);
teacherMenuBar.add(functionMenu);
teacherMenuBar.add(helpMenu);
//将菜单栏添加到框架中
setJMenuBar(teacherMenuBar);
JLabel welcomeLabel = new JLabel("欢迎使用学生信息管理系统", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("TimesRoman",Font.BOLD,30));
welcomeLabel.setForeground(Color.RED);
//创建各个菜单面板
TeacherPanel modifyPasswordPanel = new TeacherPanel(0);
//TeacherPanel nameListPanel = new TeacherPanel(1); 此语句添加到监听器中了
//TeacherPanel gradePanel = new TeacherPanel(2); 此语句添加到方法中了
// TeacherPanel queryPanel = new TeacherPanel(3);
// TeacherPanel selfInfoPanel = new TeacherPanel(4);
//添加各个卡片
myPanel = new JPanel();
card = new CardLayout();
myPanel.setLayout(card);
myPanel.add(welcomeLabel, "welcomeLabel");
myPanel.add(modifyPasswordPanel, "modifyPasswordPanel");
//myPanel.add(nameListPanel, "nameListPanel");
// myPanel.add(gradePanel, "gradePanel");
// myPanel.add(selfInfoPanel, "selfInfoPanel");
add(myPanel);
validate();
}
//the menu action listener
private class TeacherMenuAction extends AbstractAction
{
//两个构造器
public TeacherMenuAction(String s)
{
super(s);
}
public TeacherMenuAction(String s, ImageIcon icon)
{
super(s, icon);
}
public void actionPerformed(ActionEvent e)
{
if(getValue(Action.NAME).equals("修改密码")) //修改密码监听
{
card.show(myPanel, "modifyPasswordPanel");
}
else if(getValue(Action.NAME).equals("选课名单")) //哈哈 389页如何得到字符串
{
TeacherPanel nameListPanel = new TeacherPanel(1);
myPanel.add(nameListPanel, "nameListPanel");
card.show(myPanel, "nameListPanel");
}
else if(getValue(Action.NAME).equals("成绩管理")) //哈哈 389页如何得到字符串
{
TeacherPanel gradePanel = new TeacherPanel(2);
myPanel.add(gradePanel, "gradePanel");
card.show(myPanel, "gradePanel");
}
else if(getValue(Action.NAME).equals("查询统计"))
{
TeacherPanel queryPanel = new TeacherPanel(3);
myPanel.add(queryPanel, "queryPanel");
card.show(myPanel, "queryPanel");
}
else if(getValue(Action.NAME).equals("个人信息"))
{
TeacherPanel selfInfoPanel = new TeacherPanel(4);
myPanel.add(selfInfoPanel, "selfInfoPanel");
card.show(myPanel, "selfInfoPanel");
}
}
}
private static final int DEFAULT_WIDTH = 450, DEFAULT_HEIGHT = 300;
private JPanel myPanel;
private CardLayout card = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -