classenregister.java

来自「培训时做的学生管理系统.基于J2SE平台开发」· Java 代码 · 共 150 行

JAVA
150
字号
package cn.com.dialog.classmanagerdialog.classmanager;

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

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 cn.com.action.classmanageraction.enrgisteraction.EnregisterAction;
import cn.com.util.GBC;
import cn.com.vo.classmanagervo.ClassVO;

public class ClassEnregister extends JDialog{
	public static JPanel p5;
    public JDialog dialog;
    ActionListener action;//监听事件
	static JLabel classnum;//课程编号
	static JLabel classname;//课程名称
	static JLabel classtime;//课程时段
	static JLabel credithour;//学分
	JLabel enregistertime;
	/**
	 * 构建一个上课登记的Dialog
	 * @param title
	 * @return
	 */
	public ClassEnregister(ClassVO vo){
		BorderDemo();
		addInfo();
		getLabelInfo(vo);
		buildDialog("上课登记");
		
	}
	public void  buildDialog(String title) {
		if(dialog == null){
		addInfo();
		dialog = new JDialog();
		dialog.setName(title);
		dialog.setSize(300, 200);
		dialog.setModal(true);
		dialog.setTitle("上课登记");
		dialog.setLayout(new BorderLayout());
		dialog.add(p5);
		dialog.add(getTime(), "South");
		dialog.setLocationRelativeTo(null);
		dialog.setVisible(true);
		dialog.dispose();
		}
	}

	/**
	 * 
	 * 设置边框面板
	 */
	public void BorderDemo() {
		p5 = new JPanel();
		p5.setLayout(new GridBagLayout());
		p5.setBorder(BorderFactory.createTitledBorder("课程内容信息"));

	}

	
	/**
	 * 课程信息加载到面板
	 * 
	 */
	public static void addInfo() {
		p5.add(new JLabel("课程编号:     "), new GBC(0, 0).setFill(GBC.WEST));
		p5.add(classnum = new JLabel(), new GBC(1, 0).setInsets(10).setFill(
				GBC.WEST));
		p5.add(new JLabel("课程名称:     "), new GBC(3, 0).setFill(GBC.WEST));
		p5.add(classname = new JLabel(), new GBC(4, 0).setInsets(10).setFill(
				GBC.WEST));
		p5.add(new JLabel("课程时段:     "), new GBC(0, 1).setFill(GBC.WEST));
		p5.add(classtime = new JLabel(), new GBC(1, 1).setInsets(10).setFill(
				GBC.WEST));
		p5.add(new JLabel("学分:         "), new GBC(3, 1).setFill(GBC.WEST));
		p5.add(credithour = new JLabel(), new GBC(4, 1).setInsets(10).setFill(
				GBC.WEST));
	}

	/**
	 * 登记时间和登记、退出按钮
	 */
	public JPanel getTime() {
		
		Calendar now = Calendar.getInstance();
		String date = now.get(Calendar.YEAR) + "-"
				+ (now.get(Calendar.MONTH) + 1) + "-"
				+ now.get(Calendar.DAY_OF_MONTH) + " "
				+ now.get(Calendar.HOUR_OF_DAY) + ":"
				+ now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND);
		System.out.println(date.toString());

		JPanel panel = new JPanel();
		panel.setLayout(new GridBagLayout());
		panel.add(new JLabel("登记时间:     "), new GBC(0, 2).setFill(GBC.WEST));
		panel.add(new JLabel(date.toString()), new GBC(1, 2).setInsets(10)
				.setFill(GBC.WEST));
		panel.add(buildButton("登记"),new GBC(0,3).setInsets(10).setFill(GBC.WEST));
		panel.add(buildButton("退出"),new GBC(1,3).setInsets(10).setFill(GBC.WEST));
		return panel;
	}
	
	/**
	 * 隐形标签得值
	 */
	public void getLabelInfo(ClassVO vo){
		addInfo();
		classnum.setText(Integer.toString(vo.getClassID()));
		classname.setText(vo.getClassname());
		classtime.setText(vo.getClasstime());
		credithour.setText(Integer.toString(vo.getCredithour()));
	}
	
	/**
	 * 构建有名字的按钮
	 * 
	 * @param name按钮名字
	 * @return
	 */
	public JButton buildButton(String name) {
		JButton button = new JButton(name);
		action = new EnregisterAction(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 EnregisterAction(this);
		button.addActionListener(action);
		return button;
	}

}

⌨️ 快捷键说明

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