⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classadd.java

📁 培训时做的学生管理系统.基于J2SE平台开发
💻 JAVA
字号:
package cn.com.dialog.classmanagerdialog.classmanager;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import cn.com.action.classmanageraction.classaddaction.ClassAddAction;
import cn.com.util.GBC;

public class ClassAdd {
	public JDialog dialog;
	ClassManager manager;
	ActionListener action;
	JPanel p5;//设置边框
	public static JTextField text;//放学生学号
	public static JLabel label;//学生姓名
	JTable table;
	/**
	 * 构建一个增加课程的Dialog
	 * @param title
	 * @return
	 */
	public JDialog buildDialog(String title){
		if(dialog == null){
			dialog = new JDialog();
			dialog.setName(title);
			dialog.setSize(900,600);
			dialog.setModal(true);
			dialog.setLocationRelativeTo(null);
			BorderDemo();
			dialog.add(getClassInfo());
			dialog.add(getLabel(),"South");
			dialog.setVisible(true);
			dialog.dispose();
		}
		return dialog;
	}
	/**
	 * 设置边框
	 *
	 */
	public void BorderDemo(){
	    p5 = new JPanel();
	    p5.setLayout(new GridBagLayout());
		p5.setBorder(BorderFactory.createTitledBorder("课程内容"));
		addInfo();
//		this.add(p4,"South");
		dialog.setLayout(new BorderLayout());
		dialog.add(p5,"North");
	}
	
	/**
	 * 获得被选学生的学号和姓名
	 *
	 */
	public void addInfo(){
		p5.add(new JLabel("学生学号:"),new GBC(0,0).setFill(GBC.WEST));
		p5.add(text = new JTextField(10),new GBC(2,0).setInsets(14).setFill(GBC.WEST));
		p5.add(new JLabel("学生姓名:"),new GBC(4,0).setFill(GBC.WEST));
		p5.add(label = new JLabel(),new GBC(6,0).setInsets(14).setFill(GBC.WEST));
		text.setEditable(false);
	    text.setText(manager.stu_ID.getText());
		label.setText(manager.stu_name.getText());
		
	}
	
	/**
	 * 构建选择课程的JTabbedPane面板
	 * @return
	 */
	public JTabbedPane getClassInfo(){
		JTabbedPane pane = new JTabbedPane();
		JPanel panel1 = new JPanel();
		panel1.setLayout(new BorderLayout());
		panel1.add(getJScrollPane());
		pane.add("选择课程", panel1);
		return pane;
	}
	
	public JScrollPane getJScrollPane() {
		JScrollPane scrollpane = new JScrollPane(buildJTable());
		
		return scrollpane;
	}

	/**
	 * 构造表对象
	 * 
	 * @return
	 */
	public  JTable buildJTable() {
		 String[] str = { "课程编号", "课程名称", "课时", "课程时段", "学分", "课程状态",
				"执教老师编号", "执教老师姓名", "职务", "课程备注" };
		if (table == null) {
			Object[][] data = {};
			DefaultTableModel model = new DefaultTableModel(data, str);
			table = new JTable(model);
		}
		return table;
	}
	
	/**
	 * 统计选项
	 * @return
	 */
	public JPanel getLabel(){
		JPanel panel = new JPanel();
		panel.add(buildButton("保存"));
		panel.add(buildButton("退出"));
	    return panel;
	}
	
	/**
	 * 构建有名字的按钮
	 * 
	 * @param name按钮名字
	 * @return
	 */
	public JButton buildButton(String name) {
		JButton button = new JButton(name);
		action = new ClassAddAction(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 ClassAddAction(this);
		button.addActionListener(action);
		return button;
	}
//	public static void main(String[] args){
//		 ClassAdd t = new ClassAdd();
//		 t.buildDialog("增加课程");
//	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -