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

📄 modelnetimpl.java~16~

📁 一个可以实现联网售票的火车售票管理系统
💻 JAVA~16~
字号:
package train.client;

import train.mvc.*;
import train.parameter.*;
import java.util.*;
import javax.swing.table.*;
import train.command.*;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: 沈阳化工学院计算机</p>
 *
 * @author 彭胜勇 胡林
 * @version 1.0
 */
public class ModelNetImpl extends AbstractTableModel implements Model {
    Client client;
    View view;
    List list;
    TableModelTrain tableModelTrain;
    public ModelNetImpl() {
        this.client = new Client(CommonConstant.localhost,
                                 CommonConstant.localport);
        client.connect();
    }

    public void addViewListener(View view, TableModelTrain tableModelTrain) {
        this.view = view;
        this.tableModelTrain = tableModelTrain;
    }



    public void deleteTicket(Ticket ticket) {
        DeleteTicketCommand deleteTicketCommand = new DeleteTicketCommand(ticket);
        client.write(deleteTicketCommand);
        deleteTicketCommand = (DeleteTicketCommand) client.read();

    }


    public void insertTrain(Train train) {
        InsertTrainCommand insertTrainCommand = new InsertTrainCommand(train);
        client.write(insertTrainCommand);
        insertTrainCommand = (InsertTrainCommand) client.read();
        if (!insertTrainCommand.fail) {
            this.refreshTrainTable();
        } else {
            try {
                throw new Exception(" Insert " + train + " fail!");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    }

    public List getTrain() {
        GetTrainCommand getTrainCommand = new GetTrainCommand();
        client.write(getTrainCommand);
        Object obj = client.read();
        getTrainCommand = (GetTrainCommand) obj;
        return getTrainCommand.getList();
    }
    public List getStation() {
         GetStationCommand getStationCommand = new GetStationCommand();
         client.write(getStationCommand);
         Object obj = client.read();
         getStationCommand = (GetStationCommand) obj;
         return getStationCommand.getList();
     }



    public List queryTrainWiID(String trainID) {
        QueryTrainWiIDCommand  queryTrainWiIDCommand = new QueryTrainWiIDCommand(trainID);
        client.write(queryTrainWiIDCommand);
        Object obj = client.read();
        queryTrainWiIDCommand = (QueryTrainWiIDCommand) obj;
        return queryTrainWiIDCommand.getTrainList();
    }
    public List queryStation(String staIndex) {
        QueryStationCommand  queryStationCommand = new QueryStationCommand(staIndex);
        client.write(queryStationCommand);
        Object obj = client.read();
        queryStationCommand = (QueryStationCommand) obj;
        return queryStationCommand.getStationList();
    }

    public List queryTrainWiSta(String fromSta,String endSta) {
        QueryTrainWiStaCommand queryTrainWiStaCommand = new QueryTrainWiStaCommand(fromSta,endSta);
        client.write(queryTrainWiStaCommand);
        Object obj = client.read();
        queryTrainWiStaCommand = (QueryTrainWiStaCommand) obj;
        return queryTrainWiStaCommand.getTrainList();
    }


    public int getColumnCount() {
        return 0;
    }

    public int getRowCount() {
        return 0;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        return null;
    }


    public void refreshTrainTable() {
        this.view.refreshTableTrainChange();
    }

    public int getIndex(Object obj, int objType) {
        int index = 0;
        switch (objType) {
        case 0: //CommonConstant.objUser
            Train train = (Train) obj;
            list = this.getTrain();
            /*for (; index < list.size(); index++) {
                User userTest = (User) list.get(index);
                if (userTest.getUserID().equals(user.getUserID())) {
                    return index;
                }
            }*/
            break;
        default:
            index = -1;
            break;
        }
        return index;

    }
}

⌨️ 快捷键说明

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