📄 studentsframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
a student frame with menus
public class StudentsFrameTest
{
public static void main(String[] args)
{
StudentsFrame myFrame = new StudentsFrame();
myFrame.setVisible(true);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
*/
public class StudentsFrame extends JFrame
{
public StudentsFrame()
{
setTitle("学生选课管理系统(学生)");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setLocation(350, 200);
setResizable(false);
//add menu bar
JMenu systemMenu = new JMenu("系统维护");
systemMenu.add(new StudentMenuAction("修改密码", 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 StudentMenuAction("课程修读"));
functionMenu.add(new StudentMenuAction("选课申请"));
functionMenu.add(new StudentMenuAction("成绩查询"));
functionMenu.add(new StudentMenuAction("个人信息"));
JMenu helpMenu = new JMenu("帮助");
helpMenu.add(new StudentMenuAction("说明"));
helpMenu.add(new StudentMenuAction("关于"));
//add all top-level menus to menu bar
JMenuBar myMenuBar = new JMenuBar();
setJMenuBar(myMenuBar);
myMenuBar.add(systemMenu);
myMenuBar.add(functionMenu);
myMenuBar.add(helpMenu);
//add welcome panel
JLabel welcomeLabel = new JLabel("欢迎使用学生信息管理系统", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("TimesRoman",Font.BOLD,30));
welcomeLabel.setForeground(Color.RED);
//创建各个菜单面板
StudentPanel modifyPasswordPanel = new StudentPanel(0);
//StudentPanel classesPanel = new StudentPanel(1);
StudentPanel courseApplyPanel =new StudentPanel(2);
StudentPanel selfInfoPanel = new StudentPanel(4);
//添加各个卡片
myPanel = new JPanel();
card = new CardLayout();
myPanel.setLayout(card);
myPanel.add(welcomeLabel, "welcomeLabel");
myPanel.add(modifyPasswordPanel, "modifyPasswordPanel");
//myPanel.add(classesPanel, "classesPanel"); //此语句加入到监听器方法中了,目的是可以选课后及时更新
//myPanel.add(gradePanel,"gradePanel");
myPanel.add(courseApplyPanel, "courseApplyPanel");
myPanel.add(selfInfoPanel, "selfInfoPanel");
add(myPanel);
validate();
}
/**
the menu action listener
*/
private class StudentMenuAction extends AbstractAction
{
// 两个构造器
public StudentMenuAction(String name)
{
super(name);
}
public StudentMenuAction(String name, Icon icon)
{
super(name, icon);
}
// the action performed method
public void actionPerformed(ActionEvent e)
{
if(getValue(Action.NAME).equals("修改密码"))
{
card.show(myPanel, "modifyPasswordPanel");
}
else if(getValue(Action.NAME).equals("课程修读")) //哈哈 389页如何得到字符串
{
StudentPanel classesPanel = new StudentPanel(1);
myPanel.add(classesPanel, "classesPanel");
card.show(myPanel, "classesPanel");
}
else if(getValue(Action.NAME).equals("选课申请"))
{
card.show(myPanel, "courseApplyPanel");
}
else if(getValue(Action.NAME).equals("成绩查询"))
{
StudentPanel gradePanel = new StudentPanel(3);
myPanel.add(gradePanel, "gradePanel");
card.show(myPanel, "gradePanel");
}
else if(getValue(Action.NAME).equals("个人信息"))
{
card.show(myPanel, "selfInfoPanel");
}
else if(getValue(Action.NAME).equals("关于"))
{
JOptionPane.showMessageDialog(StudentsFrame.this,
" 作者:李常友\n指导老师:龙毅宏",
"作品信息",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("01.gif"));
return;
}
else if(getValue(Action.NAME).equals("说明"))
{
String s = " 本系统是用JAVA语言编写的,可以在\n"
+"任何安装了相应的JAVA虚拟机的系统使用。\n";
JOptionPane.showMessageDialog(StudentsFrame.this, s, "使用说明",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("02.gif"));
return;
}
}
}
private static final int DEFAULT_WIDTH = 450;
private static final int DEFAULT_HEIGHT = 300;
private CardLayout card;
private JPanel myPanel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -