?? frmcourseadd.java
字號(hào):
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() {
//初始化數(shù)據(jù)庫(kù)連接信息
super();
try {
DBConnectionManager.setParameter("sun.jdbc.odbc.JdbcOdbcDriver",
"jdbc:odbc:sun","","");
} catch (MyJDBCException e1) {
// TODO 自動(dòng)生成 catch 塊
e1.printStackTrace();
}
initialize();
//編寫列出所有學(xué)生信息的代碼
//學(xué)生信息列表通過(guò)JTable列出
//control類中返回所有學(xué)生信息,這些信息通過(guò)list存儲(chǔ)
//問(wèn)題轉(zhuǎn)換為把list中的信息,顯示到j(luò)table中
//構(gòu)造jtable中的數(shù)據(jù)適配器類
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 自動(dòng)生成 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 自動(dòng)生成方法存根
if(e.getSource()==this.jButtonAdd){
if(this.tbl.getSelectedRow()<0){
JOptionPane.showMessageDialog(this,"請(qǐng)選擇課程!");
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 自動(dòng)生成 catch 塊
JOptionPane.showMessageDialog(this,e1.getMessage());
e1.printStackTrace();
}
//如果編寫完成(點(diǎn)擊保存),則重新顯示列表內(nèi)容
this.tbl.validate();
this.validate();
this.repaint();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -