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

📄 kechengpanel.java

📁 Java写的一个学员系统
💻 JAVA
字号:
package cn.st.ui;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

import cn.st.data.CoursesInfo;
import cn.st.data.DataBaseConnector;


public class KeChengPanel extends JPanel{

	private static final long serialVersionUID = 1L;

	private JScrollPane jScrollPane = null;

	private JTable jTable = null;

	private JLabel jLKeChengName = null;

	private JLabel jLKeChengNum = null;

	private JTextField jTKeChengName = null;

	private JTextField jTKeChengNum = null;

	private JButton jBNew = null;

	private JButton jBModify = null;

	private JButton jBDelete = null;



	private final static String NEW = "new";

	private final static String NEW_ENTER = "newEnter";

	private final static String MODIFY = "modify";

	private final static String MODIFY_ENTER = "modifyEnter";

	private final static String DELETE = "delete";

	private CoursesInfo ci = null;  //  @jve:decl-index=0:

	private List<CoursesInfo> list = null;
	/**
	 * This method initializes jScrollPane
	 *
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(7, 10, 328, 107));
			jScrollPane.setViewportView(getJTable());
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable
	 *
	 * @return javax.swing.JTable
	 */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
			jTable.setSelectionBackground(Color.yellow);
			jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		}
		return jTable;
	}

	/**
	 * This method initializes jTKeChengName
	 *
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTKeChengName() {
		if (jTKeChengName == null) {
			jTKeChengName = new JTextField();
			jTKeChengName.setEnabled(false);
			jTKeChengName.setBounds(new Rectangle(77, 133, 91, 21));
		}
		return jTKeChengName;
	}

	/**
	 * This method initializes jTKeChengNum
	 *
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTKeChengNum() {
		if (jTKeChengNum == null) {
			jTKeChengNum = new JTextField();
			jTKeChengNum.setEnabled(false);
			jTKeChengNum.setBounds(new Rectangle(242, 133, 91, 21));
		}
		return jTKeChengNum;
	}

	/**
	 * This method initializes jBNew
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJBNew() {
		if (jBNew == null) {
			jBNew = new JButton();
			jBNew.setMnemonic(KeyEvent.VK_UNDEFINED);
			jBNew.setText("添加");
			jBNew.setName("");
			jBNew.setBounds(new Rectangle(45, 179, 62, 24));
			jBNew.setActionCommand(NEW);

		}
		return jBNew;
	}

	/**
	 * This method initializes jBModify
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJBModify() {
		if (jBModify == null) {
			jBModify = new JButton();
			jBModify.setMnemonic(KeyEvent.VK_UNDEFINED);
			jBModify.setText("修改");
			jBModify.setName("");
			jBModify.setBounds(new Rectangle(131, 179, 62, 24));
			jBModify.setActionCommand(MODIFY);

		}
		return jBModify;
	}

	/**
	 * This method initializes jBDelete
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJBDelete() {
		if (jBDelete == null) {
			jBDelete = new JButton();
			jBDelete.setMnemonic(KeyEvent.VK_UNDEFINED);
			jBDelete.setText("删除");
			jBDelete.setName("");
			jBDelete.setBounds(new Rectangle(218, 179, 61, 24));
			jBDelete.setActionCommand(DELETE);

		}
		return jBDelete;
	}

	/**
	 * This is the default constructor
	 */


	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	private void initialize() {
		jLKeChengNum = new JLabel();
		jLKeChengNum.setText("课程号:");
		jLKeChengNum.setBounds(new Rectangle(171, 133, 66, 21));
		jLKeChengName = new JLabel();
		jLKeChengName.setText("课程名称:");
		jLKeChengName.setBounds(new Rectangle(8, 133, 66, 21));
		this.setSize(341, 225);
		this.setLayout(null);
		this.add(getJScrollPane(), null);
		this.add(jLKeChengName, null);
		this.add(jLKeChengNum, null);
		this.add(getJTKeChengName(), null);
		this.add(getJTKeChengNum(), null);
		this.add(getJBNew(), null);
		this.add(getJBModify(), null);
		this.add(getJBDelete(), null);
	}


		/**
	 * 添加、修改、删除课程
	 * @param command
	 */

	/**
	 * 根据UI里的值构造一个学生对象
	 *
	 * @param student
	 * @return
	 * @throws ParseException
	 */
	private CoursesInfo builderCoursesInfoByUI(CoursesInfo ci)
			throws ParseException {

		ci.setName(this.getJTKeChengName().getText());
		ci.setNumber(this.getJTKeChengNum().getText());

		return ci;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JFrame jf = new JFrame();
		jf.add(new KeChengPanel());
		jf.setVisible(false);
		jf.setVisible(true);
		jf.setSize(350, 230);
	}

	public void valueChanged(ListSelectionEvent arg0) {
		ListSelectionModel lsm =  (ListSelectionModel) arg0.getSource();
		int i = lsm.getMinSelectionIndex();
		if(i >= 0) {
			String num = (String) this.getJTable().getModel().getValueAt(i, 1);

			if(ci != null) {
				this.getJTKeChengName().setText(this.ci.getName());

				this.getJTKeChengNum().setText(this.ci.getNumber());
			}
		}
	}

}

⌨️ 快捷键说明

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