s1(java)项目实战(固定资产管理)(tools

    技术2022-05-11  72

    package tools;

    /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2007</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */import java.util.*;

    import javax.swing.table.*;

    public class Mytable extends AbstractTableModel {    private Vector content = null;    private String[] title;    private String user = "";    private int tname = 0;    public Mytable(String _user) {        user = _user;    }

        public Mytable() {        try {            jbInit();        } catch (Exception ex) {            ex.printStackTrace();        }    }

        public Mytable(int _tname) {        tname = _tname;    }

        //获取title    public void setTitle(String[] s) {        title = s;    }

        //获取content    public void setContent(Vector v) {        content = v;    }

        //获取列名    public String getColumnName(int col) {        return title[col];    }

        //获取行数    public int getRowCount() {        return content.size();    }

        //获取列数    public int getColumnCount() {        return title.length;    }

        //不能编辑    public boolean isCellEditable(int row, int col) {        if (tname == 0) {            if (col == 0) {                return false;            } else {                if (user.equals("admin")) {                    if ((col == 1) && (row == 0)) {                        return false;                    } else {                        return true;                    }                } else {                    return true;                }            }        } else if(tname == 1){            if (col == 0 || col == 2) {                return false;            } else {                return true;            }        }else if(tname == 3)        {            if(col == 0 || col == 6 ||col ==  5)            {                return  false;            }else            {                return true;            }

            }else        {            return false;        }    }

        //更改值    public void setValueAt(Object value, int row, int col) {        ((Vector) content.get(row)).remove(col);        ((Vector) content.get(row)).add(col, value);        this.fireTableCellUpdated(row, col);    }

        public void clear() {        for (int i = content.size() - 1; i >= 0; i--) {            content.remove(i);        }    }

        //删除    public void removeRow(int frist, int count) {        for (int i = frist + count; i >= frist; i--) {            content.remove(i);        }    }

        //取得行值    public Object getValueAt(int row, int col) {        return ((Vector) content.get(row)).get(col);    }

        private void jbInit() throws Exception {    }


    最新回复(0)