⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerinfomodel.java

📁 J2ee中java网络编程的网络游戏lottery
💻 JAVA
字号:
package bingo.shared;import javax.swing.table.*;import java.util.Vector;class PlayerInfoModel extends AbstractTableModel {    protected static int NUM_COLUMNS = 4;    protected static int START_NUM_ROWS = 5;    protected int nextEmptyRow = 0;    protected int numRows = 0;    static final public String idName = "玩家ID";    static final public String playerName = "玩家名称";    static final public String cardNumName = "#卡片数量";    static final public String wolfNumName = "#诈唬次数";    protected Vector data = null;    public PlayerInfoModel() {        data = new Vector();    }    public String getColumnName(int column) {	switch (column) {	  case 0:	    return idName;	  case 1:	    return playerName;	  case 2:	    return cardNumName;	  case 3:	    return wolfNumName;	}	return "";    }    //XXX Should this really be synchronized?    public synchronized int getColumnCount() {        return NUM_COLUMNS;    }    public synchronized int getRowCount() {        if (numRows < START_NUM_ROWS) {            return START_NUM_ROWS;        } else {            return numRows;        }    }    public synchronized Object getValueAt(int row, int column) {	try {            PlayerRecord p = (PlayerRecord)data.elementAt(row);            switch (column) {              case 0:                return new Integer(p.ID);              case 1:                return p.name;              case 2:                return new Integer(p.numCards);              case 3:                return new Integer(p.wolfCries);            }	} catch (Exception e) {	}	return "";    }    public synchronized void updatePlayer(PlayerRecord playerRecord) {        int ID = playerRecord.ID; //find the ID        PlayerRecord p = null;        int index = -1;         boolean found = false;	boolean addedRow = false;                int i = 0;        while (!found && (i < nextEmptyRow)) {            p = (PlayerRecord)data.elementAt(i);            if (p.ID == ID) {                found = true;                index = i;            } else {                i++;            }        }        if (found) { //update old player	    data.setElementAt(playerRecord, index);        } else { //add new player	    if (numRows <= nextEmptyRow) {		//add a row                numRows++;		addedRow = true;            }            index = nextEmptyRow;	    data.addElement(playerRecord);	}            nextEmptyRow++;	//Notify listeners that the data changed.	if (addedRow) {	    fireTableRowsInserted(index, index);	} else {	    fireTableRowsUpdated(index, index);	}    }    public synchronized void clear() {	int oldNumRows = numRows;        numRows = START_NUM_ROWS;	data.removeAllElements();        nextEmptyRow = 0;	if (oldNumRows > START_NUM_ROWS) {	    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);	}	fireTableRowsUpdated(0, START_NUM_ROWS - 1);    }}

⌨️ 快捷键说明

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