📄 typehandler.java~28~
字号:
package card;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class typehandler implements ActionListener,ItemListener{
typeDialog td;
DatabaseOperate dp=new DatabaseOperate();
typemodel tm=new typemodel();
public typehandler(typeDialog d) {//-------------------
td=d;
setCmbtpid();//设置类别编号
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="create"){
tm.setTyid(td.cmbtpid.getSelectedIndex());//------------------------
tm.setTyname(td.txttpname.getText().trim());
if( dp.typeinsert(tm)){
JOptionPane.showMessageDialog(null,"新建成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"新建失败","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
if(e.getActionCommand()=="update"){
tm.setTyid(td.cmbtpid.getSelectedIndex());//------------------------
tm.setTyname(td.txttpname.getText().trim());
if(dp.typeupdate(tm) ){
JOptionPane.showMessageDialog(null,"更新成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"更新失败","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
if(e.getActionCommand()=="dele"){
tm.setTyid(td.cmbtpid.getSelectedIndex());//------------------------
tm.setTyname(td.txttpname.getText().trim());
if(dp.typedelete(tm) ){
JOptionPane.showMessageDialog(null,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"删除失败","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
}
public void setCmbtpid(){//更新类别信息
td.cmbtpid.removeAllItems();
td.cmbtpid.addItem("");
ArrayList arr=dp.selectType();
int n=0;
for(int i=0;i<arr.size();i++){
typemodel tm=(typemodel)arr.get(i);
n=tm.getTyid();
td.cmbtpid.addItem(String.valueOf(n).trim());
}
if(td.getTitle().equals("增加类别")){
td.cmbtpid.addItem(String.valueOf(n+1).trim());
td.cmbtpid.setSelectedItem(String.valueOf(n+1).trim());
td.cmbtpid.setEnabled(false);
}
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource().equals(td.cmbtpid)){
ArrayList arr=dp.selectType();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -