📄 classmanager.java
字号:
package cn.com.dialog.classmanagerdialog.classmanager;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import cn.com.action.classmanageraction.ClassInfoAction;
import cn.com.util.GBC;
import cn.com.vo.classmanagervo.ClassStudentVo;
public class ClassManager {
JDialog panel;
JSplitPane splitPane = null;
static JTable table;
static JTable table1;
ActionListener action;
public JComboBox c;
public static JTextField text;
public static JLabel stu_name,// 学生姓名
stu_ID;// 学号
public JLabel stu_sex,// 学生性别
qqNo,// qq号码
stu_tel,// 电话号码
stu_email,// 电子邮箱
grade,// 年级
school,// 学校
speciality,// 专业
g_No;// 组号
/**
* 单子设计模式,创建一个Dialog
*
* @param title标题
* @return
*/
public JDialog buildPanel(String title) {
if (panel == null) {
initLabel();
panel = new JDialog();
// panel.setBorder(BorderFactory.createTitledBorder(title));
panel.setTitle(title);
// panel.setModal(true);
// panel.setSize(1300, 800);
panel.setSize(1000, 700);
panel.add(MainPanel());
panel.dispose();
panel.setLocationRelativeTo(null);
panel.setModal(true);
panel.setVisible(true);
}
return panel;
}
/**
* 标签的初始化
*
*/
private void initLabel() {
stu_ID = new JLabel();
stu_name = new JLabel();
stu_sex = new JLabel();
qqNo = new JLabel();
stu_email = new JLabel();
stu_tel = new JLabel();
grade = new JLabel();
school = new JLabel();
speciality = new JLabel();
g_No = new JLabel();
}
/**
* 标签得到从从数据库中传来的数据信息
*
* @param vo
*/
public void getLabelInfo(ClassStudentVo vo) {
stu_ID.setText(Integer.toString(vo.getStu_ID()));
stu_name.setText(vo.getStu_name());
stu_sex.setText(vo.getStu_sex());
qqNo.setText(Integer.toString(vo.getQqNo()));
stu_tel.setText(Integer.toString(vo.getStu_tel()));
stu_email.setText(vo.getStu_email());
grade.setText(vo.getGrade());
school.setText(vo.getSchool());
speciality.setText(vo.getSpeciality());
g_No.setText(Integer.toString(vo.getG_No()));
}
/**
* 在桌面上显示课程表信息
*
* @return
*/
private JPanel getPanel1() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(new JLabel("学生学号:"), new GBC(0, 0).setFill(GBC.WEST));
panel.add(stu_ID, new GBC(1, 0).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("学 校:"), new GBC(2, 0).setFill(GBC.WEST));
panel.add(school, new GBC(3, 0).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("所在的组号:"), new GBC(4, 0).setFill(GBC.WEST));
panel.add(g_No, new GBC(5, 0).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("学生姓名:"), new GBC(0, 1).setFill(GBC.WEST));
panel.add(stu_name, new GBC(1, 1).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("年 级:"), new GBC(2, 1).setFill(GBC.WEST));
panel.add(grade, new GBC(3, 1).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("电话号码:"), new GBC(4, 1).setFill(GBC.WEST));
panel.add(stu_tel, new GBC(5, 1).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("性 别:"), new GBC(0, 2).setFill(GBC.WEST));
panel.add(stu_sex, new GBC(1, 2).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("专 业:"), new GBC(2, 2).setFill(GBC.WEST));
panel.add(speciality, new GBC(3, 2).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("QQ 号码:"), new GBC(4, 2).setFill(GBC.WEST));
panel.add(qqNo, new GBC(5, 2).setInsets(4).setWeight(8, 0));
panel.add(new JLabel("e_mail:"), new GBC(0, 4).setFill(GBC.WEST));
panel.add(stu_email, new GBC(1, 4).setInsets(14).setWeight(8, 0));
panel
.add(
new JLabel(
"-------------------------------"),
new GBC(0, 3).setFill(GBC.WEST));
return panel;
}
/**
* 构建查询的面板
*
* @return
*/
public JPanel getPanel2() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
String[] str = { " 学生 ", " 老师 " };
// Box box = new Box(BoxLayout.X_AXIS);
// box.add(Box.createHorizontalStrut(15));
panel.add(new JLabel("请输入编号:"));
panel.add(text = new JTextField(10));
panel.add(new JLabel(" "));
panel.add(c = new JComboBox(str));
panel.add(new JLabel(" "));
panel.add(buildButton(" 查询 "));
panel.add(new JLabel(" "));
panel.add(buildButton("浏览课程"));
// panel.add(Box.createHorizontalStrut(15), new GBC(0, 0).setInsets(5)
// .setWeight(0, 0).setFill(GBC.WEST));
// panel.add(new JLabel("请输入编号:"), new GBC(1, 0, 2, 1)
// .setFill(GBC.HORIZONTAL));
// panel.add(text = new JTextField(10), new GBC(3, 0, 1, 1).setInsets(0).setWeight(
// 3, 0).setFill(GBC.WEST));
//
// panel.add(c = new JComboBox(str), new GBC(5, 0)
// .setFill(GBC.WEST));
// panel.add(buildButton("查询"), new GBC(6, 0).setInsets(20)
// .setWeight(0, 0).setFill(GBC.WEST));
// panel.add(buildButton("浏览全部课程"), new GBC(7, 0).setInsets(20).setWeight(
// 0, 0).setFill(GBC.WEST));
// panel.add(box);
return panel;
}
/**
* 获得课程统计资料
*
* @return
*/
public JTabbedPane getClassstatInfo() {
JTabbedPane pane = new JTabbedPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
panel1.setLayout(new BorderLayout());
// Box box = new Box(BoxLayout.X_AXIS);
// box.add(Box.createHorizontalStrut(400));
panel2.add(buildButton("学生选课"));
panel2.add(buildButton("课程注销"));
panel2.add(buildButton("上课登记"));
panel1.add(panel2, "North");
panel1.add(getJScrollPane());
pane.add("学生课程统计", panel1);
return pane;
}
/**
* 存放上课登记资料
*
* @return
*/
public JTabbedPane getClassstatInfo1() {
JTabbedPane pane = new JTabbedPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout(FlowLayout.LEFT));
panel1.setLayout(new BorderLayout());
// Box box = new Box(BoxLayout.X_AXIS);
// box.add(Box.createHorizontalStrut(10));
// JLabel label1 = new JLabel(" ");
// JLabel label2 = new JLabel(" ");
panel2.add(buildButton("出勤查询"));
// panel2.add(label1);
// panel2.add(label2);
panel1.add(panel2, "North");
panel1.add(getJScrollPane1());
pane.add("学生上课登记", panel1);
return pane;
}
/**
* 构建分区的panel面板
*
* @return
*/
public JSplitPane buildSplitPane() {
if (splitPane == null) {
splitPane = new JSplitPane();
splitPane.setOneTouchExpandable(true);
splitPane.setLeftComponent(getClassstatInfo());
splitPane.setRightComponent(getClassstatInfo1());
splitPane.setDividerLocation(750);
}
return splitPane;
}
public JPanel MainPanel() {
JPanel panel1 = new JPanel(new BorderLayout());
JPanel panel2 = new JPanel(new BorderLayout());
panel2.add(getPanel2(), "North");
panel2.add(getPanel1(), "Center");
panel1.add(panel2, "North");
panel1.add(buildSplitPane());
return panel1;
}
public JScrollPane getJScrollPane() {
JScrollPane scrollpane = new JScrollPane(buildJTable());
return scrollpane;
}
public JScrollPane getJScrollPane1() {
JScrollPane scrollpane = new JScrollPane(buildJTable1());
return scrollpane;
}
/**
* 构造表对象
*
* @return
*/
public JTable buildJTable() {
String[] str = { "课程编号", "课程名称", "课时", "课程时段", "学分", "课程状态",
"执教老师编号", "执教老师姓名", "职务", "课程备注" };
if (table == null) {
Object[][] data = {};
DefaultTableModel model = new DefaultTableModel(data, str);
table = new JTable(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
return table;
}
public JTable buildJTable1() {
String[] str1 = { "课程编号", "课程名称","登记次数" };
if (table1 == null) {
Object[][] data = {};
DefaultTableModel model = new DefaultTableModel(data, str1);
table1 = new JTable(model);
}
return table1;
}
/**
* 构建有名字的按钮
*
* @param name按钮名字
* @return
*/
public JButton buildButton(String name) {
JButton button = new JButton(name);
action = new ClassInfoAction(this);
button.addActionListener(action);
return button;
}
/**
* 创建带图标的按钮
*
* @param name
* @return
*/
private JButton buildButton(String name, String image) {
JButton button = new JButton(new ImageIcon(image));
button.setName(name);
action = new ClassInfoAction(this);
button.addActionListener(action);
return button;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -