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

📄 addcourse.java

📁 accp s1毕业项目 考试管理系统
💻 JAVA
字号:
package com.exam.ui.banzhuren;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.exam.db.bean.Course;
import com.exam.db.dao.CourseDao;
import com.exam.ui.SuperFrame;

public class AddCourse extends SuperFrame {
	private static final long serialVersionUID = 1L;

	public AddCourse() {
		try {
			init();
			this.setVisible(true);
			this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void init() {
		this.setTitle("添加科目");
		this.setSize(300, 225);
		this.setCenter();
		this.setResizable(false);

		JPanel pnlTotal = new JPanel();
		this.getContentPane().add(pnlTotal);
		pnlTotal.setLayout(null);

		final JLabel lblGrade = new JLabel("年         级");
		lblGrade.setBounds(50, 30, 70, 25);
		pnlTotal.add(lblGrade);

		final JComboBox cboGrade = new JComboBox();
		cboGrade.setBounds(120, 30, 120, 25);
		cboGrade.addItem("S1");
		cboGrade.addItem("S2");
		cboGrade.addItem("Y2");
		pnlTotal.add(cboGrade);

		final JLabel lblCouName = new JLabel("课程名称");
		lblCouName.setBounds(50, 70, 70, 25);
		pnlTotal.add(lblCouName);

		final JTextField txtCouName = new JTextField();
		txtCouName.setBounds(120, 70, 120, 25);
		pnlTotal.add(txtCouName);


		JButton btnSave = new JButton("保   存");
		btnSave.setBounds(70, 130, 70, 25);
		pnlTotal.add(btnSave);

		final JButton btnReset = new JButton("重   置");
		btnReset.setBounds(160, 130, 70, 25);
		pnlTotal.add(btnReset);

		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				txtCouName.setText("");
				cboGrade.setSelectedIndex(0);
			}
		});
		btnSave.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				String grade = (String)cboGrade.getSelectedItem();
				String couName = txtCouName.getText();
				if(couName.equals("")){
					JOptionPane.showMessageDialog(null,"请输入课程名");
					txtCouName.requestFocus();
					return;
				}
				Course course = new Course();
				course.setCouName(couName);
				course.setGrade(grade);
				CourseDao courseDao = new CourseDao();
				int result = courseDao.insertCourse(course);
				if(result == 1){
					JOptionPane.showMessageDialog(null,"保存成功!");
					dispose();
				}else{
					JOptionPane.showMessageDialog(null,"保存失败!");
					btnReset.doClick();
				}
			}			
		});
	}
}

⌨️ 快捷键说明

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