ADD file via upload

main
nxist2202005056 1 year ago
parent 3c5be41615
commit 9960147a2b

@ -0,0 +1,105 @@
package com.WR.StudentMS.view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
public class MainFarme extends JFrame {
private JTabbedPane rightPanel; // 右侧内容显示区使用JTabbedPane
private JPanel leftPanel; // 左侧功能栏
private JLabel titleLabel;// 标题标签
public MainFarme() {
setTitle("学生管理系统");
setSize(800, 600); // 设置窗口大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置窗口关闭操作
setLayout(new BorderLayout()); // 设置布局管理器
// 初始化 leftPanel 和 rightPanel
leftPanel = new JPanel();
rightPanel = new JTabbedPane();
// 添加 leftPanel 和 rightPanel 到 JFrame
add(leftPanel, BorderLayout.WEST);
add(rightPanel, BorderLayout.CENTER);
// 设置 leftPanel 的布局管理器
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
// 创建标题标签并设置华文行楷字体
titleLabel = new JLabel("学生管理系统", SwingConstants.CENTER);
Font customFont1 = new Font("华文行楷", Font.PLAIN, 24); // 您可以调整字体大小
titleLabel.setFont(customFont1);
setTitle("");
// 创建一个面板用于放置标题,并将其添加到顶部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new BorderLayout());
titlePanel.add(titleLabel, BorderLayout.CENTER);
add(titlePanel, BorderLayout.NORTH); // 添加标题面板到窗口北部
Font customFont = new Font("华文行楷", Font.PLAIN, 16);
// 添加功能按钮到左侧面板
JButton button1 = new JButton("修改个人密码");
button1.setFont(customFont);
addFunctionButton(button1.getText(), TAdminPanel.class);
JButton button2 = new JButton("专业信息管理");
button2.setFont(customFont);
addFunctionButton(button2.getText(), ZhuanyePanel.class);
JButton button3 = new JButton("班级信息管理");
button3.setFont(customFont);
addFunctionButton(button3.getText(), ClassmPanel.class);
JButton button4 = new JButton("课程信息管理");
button4.setFont(customFont);
addFunctionButton(button4.getText(), CoursemPanel.class);
JButton button5 = new JButton("学籍信息管理");
button5.setFont(customFont);
addFunctionButton(button5.getText(), RegistrationPanel.class);
JButton button6 = new JButton("成绩信息管理");
button6.setFont(customFont);
addFunctionButton(button6.getText(), TchengjiPanel.class);
JButton button7 = new JButton("奖惩信息管理");
button7.setFont(customFont);
addFunctionButton(button7.getText(), JiangchengPanel.class);
// 确保窗口在屏幕中间
setLocationRelativeTo(null);
}
private void addFunctionButton(String text, final Class<?> panelClass) {
JButton button = new JButton(text);
Font customFont = new Font("华文行楷", Font.PLAIN, 16);
button.setFont(customFont);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// 使用 panelClass 创建实例并添加到 rightPanel
JComponent panel = (JComponent) panelClass.getDeclaredConstructor().newInstance();
rightPanel.addTab(text, panel);
rightPanel.setSelectedComponent(panel);
} catch (InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException ex) {
JOptionPane.showMessageDialog(MainFarme.this, "创建面板实例失败: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
}
}
});
leftPanel.add(button); // 将按钮添加到 leftPanel
}
public static void main(String[] args) {
// 使用SwingUtilities.invokeLater确保GUI创建和更新在事件调度线程EDT上执行
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 创建MainFarme窗口实例并设置其可见性为true显示窗口
new MainFarme().setVisible(true);
}
});
}
}
Loading…
Cancel
Save