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

📄 frmcourseadd.java

📁 功能还没做全的选课系统
💻 JAVA
字号:
package com.xuanke.student.view;

import java.awt.BorderLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import com.xuanke.student.control.*;
import com.xuanke.student.model.CoursetBean;
import com.xuanke.utils.DBConnectionManager;
import com.xuanke.utils.MyJDBCException;

public class FrmCourseAdd extends JFrame implements ActionListener{

	private JPanel jContentPane = null;
	private JPanel jPanelToolBar = null;
	private JButton jButtonAdd = null;
	private CourseTablelModel ctm;
	private JTable tbl;
	/**
	 * This is the default constructor
	 */
	public FrmCourseAdd() {
		//初始化数据库连接信息
		
		super();
		try {
			DBConnectionManager.setParameter("sun.jdbc.odbc.JdbcOdbcDriver",
					"jdbc:odbc:sun","","");
		} catch (MyJDBCException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		}
		initialize();
		//编写列出所有学生信息的代码
		//学生信息列表通过JTable列出
		//control类中返回所有学生信息,这些信息通过list存储
		//问题转换为把list中的信息,显示到jtable中
		//构造jtable中的数据适配器类
		CourseManager sm=CourseManager.getInstance();
		try {
			List students=sm.findAll();
			ctm=new CourseTablelModel(students);
			tbl=new JTable(ctm);
			
			JScrollPane sp=new JScrollPane(tbl);
			this.add(sp,BorderLayout.CENTER);
			
		} catch (BusinessException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		this.validate();
		this.setVisible(true);
		
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanelToolBar(), java.awt.BorderLayout.NORTH);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanelToolBar	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelToolBar() {
		if (jPanelToolBar == null) {
			jPanelToolBar = new JPanel();
			jPanelToolBar.setPreferredSize(new java.awt.Dimension(10,60));
			jPanelToolBar.add(getJButtonAdd(), null);
		}
		return jPanelToolBar;
	}

	/**
	 * This method initializes jButtonAdd	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAdd() {
		if (jButtonAdd == null) {
			jButtonAdd = new JButton();
			jButtonAdd.setText("选课");
			jButtonAdd.addActionListener(this);
		}
		return jButtonAdd;
	}

	/**
	 * This method initializes jButtonDelete	
	 * 	
	 * @return javax.swing.JButton	
	 * 
	 * 
	 * StudentBean student=
				(StudentBean)this.ctm.getStudents().get(this.tbl.getSelectedRow());
			
			CourseManager sm=CourseManager.getInstance();
	 */

	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成方法存根
		if(e.getSource()==this.jButtonAdd){
			if(this.tbl.getSelectedRow()<0){
				JOptionPane.showMessageDialog(this,"请选择课程!");
				return;
			}
			CoursetBean student=
				(CoursetBean)this.ctm.getStudents().get(this.tbl.getSelectedRow());
			//编写student的编辑界面代码
			
			CourseManager sm=CourseManager.getInstance();
			try {
				sm.add(student.getId());
				JOptionPane.showMessageDialog(this,"选课程成功!");
			} catch (BusinessException e1) {
				// TODO 自动生成 catch 块
				JOptionPane.showMessageDialog(this,e1.getMessage());
				e1.printStackTrace();
			}
			
			//如果编写完成(点击保存),则重新显示列表内容				
			this.tbl.validate();
			this.validate();
			this.repaint();
			
		}
		
	}
		

}

⌨️ 快捷键说明

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