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

📄 coursemagdialog.java

📁 学生管理系统。使用java编程
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
								CourseQueryPane.add(FaintnessRadioButton);
								FaintnessRadioButton.setText("\u5e76\u4e14");
								FaintnessRadioButton.setBounds(84, 112, 70, 21);
								PreciFaintbuttonGroup.add(FaintnessRadioButton);
								FaintnessRadioButton
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												FaintnessRadioButtonActionPerformed(evt);
											}
										});
							}
							{
								OrRadioButton = new JRadioButton();
								CourseQueryPane.add(OrRadioButton);
								OrRadioButton.setText("\u6216\u8005");
								OrRadioButton.setBounds(161, 112, 77, 21);
								PreciFaintbuttonGroup.add(OrRadioButton);
								OrRadioButton
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												OrRadioButtonActionPerformed(evt);
											}
										});
							}
							{
								QueryLabel = new JLabel();
								CourseQueryPane.add(QueryLabel);
								QueryLabel.setText("\u81f3");
								QueryLabel.setBounds(224, 77, 21, 28);
							}
							{
								QueryTextField = new JTextField();
								CourseQueryPane.add(QueryTextField);
								QueryTextField
										.setText("\u8bf7\u8f93\u5165\u67e5\u8be2\u5b57\u6bb5");
								QueryTextField.setBounds(231, 14, 105, 28);
							}
							{
								QueryButton = new JButton();
								CourseQueryPane.add(QueryButton);
								QueryButton.setText("\u67e5\u8be2");
								QueryButton.setBounds(21, 336, 70, 21);
								QueryButton
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												try {
													QueryButtonActionPerformed(evt);
												} catch (SQLException e) {
													e.printStackTrace();
												}
											}
										});
							}
							{
								SelectRageCheckBox = new JCheckBox();
								CourseQueryPane.add(SelectRageCheckBox);
								SelectRageCheckBox
										.setText("\u662f\u5426\u9009\u62e9\u8303\u56f4");
								SelectRageCheckBox.setBounds(126, 49, 91, 21);
								SelectRageCheckBox
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												SelectRageCheckBoxActionPerformed(evt);
											}
										});
							}
							{
								FirstTextField = new JTextField();
								CourseQueryPane.add(FirstTextField);
								FirstTextField.setBounds(126, 77, 91, 28);
							}
							{
								EndTextField1 = new JTextField();
								CourseQueryPane.add(EndTextField1);
								EndTextField1.setBounds(245, 77, 91, 28);
							}
							{
								AddButton = new JButton();
								CourseQueryPane.add(AddButton);
								AddButton.setText("\u6dfb\u52a0");
								AddButton.setBounds(203, 336, 70, 21);
								AddButton
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												AddButtonActionPerformed(evt);
											}
										});
							}
							{
								ClearButton = new JButton();
								CourseQueryPane.add(ClearButton);
								ClearButton.setText("\u6e05\u7a7a");
								ClearButton.setBounds(112, 336, 70, 21);
								ClearButton
										.addActionListener(new ActionListener() {
											public void actionPerformed(
													ActionEvent evt) {
												ClearButtonActionPerformed(evt);
											}
										});
							}
							{
								QueryConditionLabel = new JLabel();
								CourseQueryPane.add(QueryConditionLabel);
								QueryConditionLabel
										.setText("\u67e5\u8be2\u6761\u4ef6");
								QueryConditionLabel.setBounds(21, 140, 84, 21);
								QueryConditionLabel
										.setForeground(new java.awt.Color(0, 0,
												255));
							}
							CourseQueryPane.setFocusCycleRoot(true);
							CourseQueryPane
									.setFocusTraversalPolicy(new ArrayFocusTraversalPolicy(
											new java.awt.Component[] {
													CourseQueryComboBox1,
													CompareComboBox,
													QueryTextField,
													SelectRageCheckBox,
													FirstTextField,
													EndTextField1,
													PrecisionRadioButton,
													FaintnessRadioButton,
													OrRadioButton, QueryButton,
													AddButton, ClearButton }));
						}
						{
							CourseQueryPanel1 = new JPanel();
							BorderLayout CourseQueryPanel1Layout = new BorderLayout();
							CourseQueryTabbedPane.addTab("学科信息", null,
									CourseQueryPanel1, null);
							CourseQueryPanel1
									.setLayout(CourseQueryPanel1Layout);
							CourseQueryPanel1
									.setPreferredSize(new java.awt.Dimension(
											497, 385));
							{
								CourseQueryScrollPane = new JScrollPane();
								CourseQueryPanel1.add(CourseQueryScrollPane,
										BorderLayout.CENTER);
								CourseQueryScrollPane
										.setBounds(7, 14, 483, 357);
								{
									// 初始化Table
									CourseQueryTableModel = new DefaultTableModel(
											row, column);
									CourseQueryTable = new JTable();
									BorderLayout CourseQueryTableLayout = new BorderLayout();
									CourseQueryTable
											.setLayout(CourseQueryTableLayout);
									CourseQueryScrollPane
											.setViewportView(CourseQueryTable);

									CourseQueryTable
											.setModel(CourseQueryTableModel);
									CourseQueryTable.setBounds(21, 420, 427,
											147);
									CourseQueryTable
											.setPreferredSize(new java.awt.Dimension(
													481, 4491));
									//设置班级表高度									CourseQueryTable.setRowHeight(24);
									CourseQueryTable
											.addMouseListener(new MouseAdapter() {
												public void mouseClicked(
														MouseEvent evt) {
													CourseQueryTableMouseClicked(evt);
												}
											});

								}
							}
						}
					}
				}
			}
			this.setSize(900, 475);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void ExitButtonActionPerformed(ActionEvent evt) {
		// TODO add your code for ExitButton.actionPerformed
		// 退出		this.dispose();
	}

	private void QueryButtonActionPerformed(ActionEvent evt)
			throws SQLException {
		// 查询		// 建立一个JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息		Vector vecData = new Vector();
		// 定义SQL语句组合项		String strSQL = "select * from  course ";
		String strSQL1 = " where ";
		String strTemp = " order by courseid ASC";

		// 组合SQL语句		if (this.vecSQL.isEmpty()) {
			strSQL += strTemp;
		} else {
			for (int i = 0; i < this.vecSQL.size(); i++) {
				strSQL1 += this.vecSQL.get(i).toString();
			}
			strSQL += strSQL1 + strTemp;
		}

		// 刷新table中数据		CourseQueryTableModel = new DefaultTableModel(row, column);
		this.CourseQueryTable.setModel(CourseQueryTableModel);
		CourseQueryTable.getTableHeader().setBounds(0, 0, 469, -273);
		// this.CourseQueryTable.setRowMargin(20);
		// 获得数据		vecData = jdbcConnection.getData(strSQL);
		// 依次为各行插入数据		if (vecData.size() > 0) {
			for (int i = 0; i < vecData.size(); i++) {
				CourseQueryTableModel.addRow((String[]) vecData.get(i));
			}
			// 显示查询数据			this.CourseQueryTabbedPane
					.setSelectedComponent(this.CourseQueryPanel1);
		} else {
			JOptionPane.showMessageDialog(this, "您查询的记录在数据库中不存在!请换一个查询条件.");
		}
	}
    /**
     * 初始化学科课表     * @throws SQLException
     */ 
	private void initTable() throws SQLException {
		// 建立一个JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息		Vector vecData = new Vector();
		// 定义SQL语句		String strSQL = "select * from  course order by courseid ASC";

		CourseQueryTableModel = new DefaultTableModel(row, column);
		this.CourseQueryTable.setModel(CourseQueryTableModel);
		BorderLayout tableHeaderLayout = new BorderLayout();
		CourseQueryTable.getTableHeader().setLayout(tableHeaderLayout);
		CourseQueryTable.getTableHeader().setPreferredSize(
				new java.awt.Dimension(481, 12));
		// this.CourseQueryTable.setRowMargin(20);
		// 获得数据		vecData = jdbcConnection.getData(strSQL);
		// 依次为各行插入数据		for (int i = 0; i < vecData.size(); i++) {
			CourseQueryTableModel.addRow((String[]) vecData.get(i));
		}
	}

	private void CourseQueryTableMouseClicked(MouseEvent evt) {
		// 鼠标点击,获取点击行数据,显示在界面上		// 定义变量 学科名,学科号,学时,学分		String strcourseId = "";
		int ncourseId = 0;
		String strcourseName = "";
		String strpreiod = "";
		int npreiod = 0;
		String strcreditHour = "";
		float fcreditHour = 0.0f;
		// 定义鼠标点击行		int nrow = 0;

		// 获取鼠标点击行		nrow = this.CourseQueryTable.getSelectedRow();
		// 获取行内数据		strcourseId = String.valueOf(this.CourseQueryTable.getValueAt(nrow, 0));
		strcourseName = String.valueOf(this.CourseQueryTable
				.getValueAt(nrow, 1));
		strpreiod = String.valueOf(this.CourseQueryTable.getValueAt(nrow, 2));
		strcreditHour = String.valueOf(this.CourseQueryTable
				.getValueAt(nrow, 3));

		// 类型转换		try {
			ncourseId = Integer.parseInt(strcourseId);
			npreiod = Integer.parseInt(strpreiod);
			fcreditHour = Float.parseFloat(strcreditHour);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		// 初始化Course对象		course.setValue(ncourseId, strcourseName, npreiod, fcreditHour);

		// 显示鼠标点击数据		this.CourseIdTextField.setText(strcourseId);
		this.CourseNameTextField.setText(strcourseName);
		this.PeriodTextField1.setText(strpreiod);
		this.CreditHourTextField1.setText(strcreditHour);

		// 新增、修改、删除按钮可用		this.NewButton.setEnabled(true);
		this.ModifyButton1.setEnabled(true);
		this.DeleteButton1.setEnabled(true);
		// 保存按钮不可用		this.SaveButton.setEnabled(false);
		// 学科号文本框不可用		this.CourseIdTextField.setEnabled(false);

	}
    
	/**
	 * 新增课程信息	 * @param evt
	 */
	private void NewButtonActionPerformed(ActionEvent evt) {
		// 新增		// 建立一个JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息		Vector vecData = new Vector();
		// 定义SQL语句		String strSQL = "";
		// 定义int型变量,MaxCouID
		int MaxCouID = 0;
		String[] strAryMaxCouID = new String[1];

		// 清空文本框		this.CourseIdTextField.setText("");
		this.CourseNameTextField.setText("");
		this.PeriodTextField1.setText("");
		this.CreditHourTextField1.setText("");

		// 新增、修改、删除按钮不可用,保存按钮可用		this.NewButton.setEnabled(false);
		this.ModifyButton1.setEnabled(false);
		this.DeleteButton1.setEnabled(false);
		this.SaveButton.setEnabled(true);
		// 学科号自动增长,显示学科号,设为不可用		// 查询学科信息表Course中最大学科号		strSQL = " Select max(courseId) from  course";
		try {
			vecData = jdbcConnection.getData(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		for (int i = 0; i < vecData.size(); i++) {

			strAryMaxCouID = (String[]) vecData.get(i);
		}

		try {
			MaxCouID = Integer.parseInt(strAryMaxCouID[0]);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		// MaxCouID加一		MaxCouID++;
		System.out.println(MaxCouID);
		// 课程号文本框显示,置为False
		this.CourseIdTextField.setText(String.valueOf(MaxCouID));
		this.CourseIdTextField.setEnabled(false);

	}
    
	/**
	 * 保存课程信息	 * @param evt
	 * @throws SQLException
	 */
	private void SaveButtonActionPerformed(ActionEvent evt) throws SQLException {
		// 保存		// 建立JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义变量 学科名,学时,学分		String strcourseID = "";
		boolean bisRight = false;
		// 定义SQL语句		String strSQL = "";
		// 定义SQL语句执行返回值 int updateLine;
		int updateLine = 0;

		// 定义Course对象		Course course = new Course();

		// 获取用户输入信息		course = getUserInput(course);
		// 用户输入校验		if (course.getCourseName().equals(null) 
				|| course.getPreiod() > 200
				|| course.getCreditHour() > 5) {
			bisRight = false;
		} else {
			bisRight = true;
		}

⌨️ 快捷键说明

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