vocabularytablemodel.java~5~

来自「辞典 这个是同学们一起编的一个辞典 JAVA开发的 希望能有用」· JAVA~5~ 代码 · 共 104 行

JAVA~5~
104
字号
package com.ui.table;import javax.swing.table.AbstractTableModel;import java.util.SortedMap;import javax.swing.table.TableModel;import java.util.TreeMap;import com.io.file.VocabularyFileReader;/** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2008</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */public class VocabularyTableModel extends AbstractTableModel{    private SortedMap sortedMap = null;    private Object[] vocabulary = null;    private Object[] pronounce = null;    public VocabularyTableModel(SortedMap map)    {        if (map != null)        {            this.setSortedMap(map);            this.vocabulary = this.sortedMap.keySet().toArray();            this.pronounce = this.sortedMap.values().toArray();        }        else        {            this.setSortedMap(new TreeMap(new VocabularyFileReader("/opt/work/workspace/jb6/JDic/src/jdic/default.voc", "").getMap()));            this.vocabulary = this.sortedMap.keySet().toArray();            this.pronounce = this.sortedMap.values().toArray();        }    }    public SortedMap getSortedMap()    {        return this.sortedMap;    }    public void setSortedMap(SortedMap map)    {        this.sortedMap = map;    }    public int getColumnCount()    {        return 2;    }    public int getRowCount()    {        return vocabulary.length;    }    public String getColumnName(int colIndex)    {        switch (colIndex)        {            case 0:                return "VOCABULARY";            case 1:                return "PRONOUNCE";            default:                return "";        }    }    public boolean isCellEditable(int rowIndex, int columnIndex)    {        if (columnIndex == 0)        {            return false;        }        else        {            return true;        }    }    public Object getValueAt(int row, int col)    {        if (col == 0)        {            return  this.vocabulary[row];        }        else        {            String pronounciation = this.pronounce[row].toString();            pronounciation = pronounciation.substring(pronounciation.indexOf("&"));            System.out.println("pronounciation is " + pronounciation);            return pronounciation;        }    }}

⌨️ 快捷键说明

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