public class CourseSearchCteacher extends JFrame implements
ActionListener{
Container contentPane;
//框架的大小
Dimension faceSize = new Dimension(300, 100); JLabel jLabel1 = new JLabel();
JTextField cTeacher = new JTextField(8); JButton searchInfo = new JButton();
public CourseSearchCteacher() { //设置标题
this.setTitle(\按课程名称查询\ this.setResizable(false);
//设置程序图标
this.setIconImage(getImage(\ try { Init();
}
catch (Exception e) { e.printStackTrace(); }
//设置运行位置,使对话框居中 Dimension
screenSize
Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation( (int) (screenSize.width - 400) / 2 ,
(int) (screenSize.height - 300) / 2 + 45);
} private void Init() throws Exception { this.setSize(faceSize);
contentPane = this.getContentPane();
contentPane.setLayout(new FlowLayout()); jLabel1.setText(\请输入授课教师名称: \
jLabel1.setFont(new Font(\ contentPane.add(jLabel1); cTeacher.setText(null);
cTeacher.setFont(new Font(\ contentPane.add(cTeacher);
=
}
}
searchInfo.setText(\确定\
searchInfo.setFont(new Font(\contentPane.add(searchInfo);
searchInfo.addActionListener(this);
/** * 事件处理 */
public void actionPerformed(ActionEvent e) { } /**
* 通过给定的文件名获得图像 */
Image getImage(String filename) { }
URLClassLoader urlLoader = (URLClassLoader)this.getClass().
getClassLoader(); URL url = null; Image image = null;
url = urlLoader.findResource(filename);
image = Toolkit.getDefaultToolkit().getImage(url); MediaTracker mediatracker = new MediaTracker(this); try { }
catch (InterruptedException _ex) { }
if (mediatracker.isErrorID(0)) { }
return image;
image = null; image = null;
mediatracker.addImage(image, 0); mediatracker.waitForID(0); Object obj = e.getSource(); if (obj == searchInfo) { //查询 ResultCourse rC }
this.dispose();
=
new
ResultCourse(\
//////////////////////////////////CrsBean.java//////////////////////
import java.util.*; import java.sql.*; import javax.swing.*; /**
* 有关课程信息数据库操作的类 */
public class CrsBean {
if(cName == null||cName.equals(\
JOptionPane.showMessageDialog(null, \请输入课程名称\错误\JOptionPane.ERROR_MESSAGE);
} else{
sql
=
\
into
return;
String colName;//列名 String colValue;//列值 int crsId;//新课程的编号 /**
* 添加课程信息 */
public void crsAdd(String num,String name, String teacher, String
Database DB = new Database(); this.cNum = num; this.cName = name; this.cTeacher = teacher; this.cPlace = place; this.cPoint= type; this.cRatio = time; String cNum; String cName; String cTeacher; String cPlace; String cPoint; String cRatio; String sNum; String sql;
ResultSet rs = null;
place, String type, String time){
course(cnum,cname,cteacher,cplace,cpoint,cratio) Ratio+\
try{
DB.OpenConn();
DB.executeUpdate(sql);
values
('\
\
JOptionPane.showMessageDialog(null,\成功添加一条新的纪录!
}
catch(Exception e){
JOptionPane.showMessageDialog(null, \保存失败\\错误\JOptionPane.ERROR_MESSAGE);
if(cName == null||cName.equals(\
JOptionPane.showMessageDialog(null, \请输入课程名称\错误\JOptionPane.ERROR_MESSAGE);
} else{
sql = \course set cname = '\cTeacher = return;
/**
* 修改课程信息 */
public void crsModify(String num, String name, String teacher, String
Database DB = new Database(); this.cNum = num; this.cName = name; this.cTeacher = teacher; this.cPlace = place; this.cPoint = type; this.cRatio = time; }
}
}
finally { }
DB.closeStmt(); DB.closeConn();
place, String type, String time){
'\'\
try{
}
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,\成功修改一条新的纪录!
\
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \更新失败\\错误\JOptionPane.ERROR_MESSAGE);
/**
* 删除课程信息 */
public void crsDel(String num){
Database DB = new Database(); this.cNum = num;
sql = \try{
DB.OpenConn();
DB.executeUpdate(sql);
}
}
}
finally { }
DB.closeStmt(); DB.closeConn();
JOptionPane.showMessageDialog(null,\成功删除一条新的纪录!\}
catch(Exception e){
System.out.println(e); e.printStackTrace();
JOptionPane.showMessageDialog(null, \删除失败\\错误\JOptionPane.ERROR_MESSAGE);
/**
* 根据课程号,搜索课程名称等相关信息 }
}
finally { }
DB.closeStmt(); DB.closeConn();