java 6 rmi,Java网络编程精解之基于MVC和RMI的分布式应用一(6)

package store;

//此处省略import语句

public class StoreViewImpl extends UnicastRemoteObject

implements StoreView,Serializable{

private transient StoreGui gui;

private StoreModel storemodel;

private Object display;

private ArrayListstoreControllers=

new ArrayList(10);

public StoreViewImpl(StoreModel model)throws RemoteException {

try{

storemodel=model;

model.addChangeListener(this);  //向model注册自身

}catch(Exception e){

System.out.println("StoreViewImpl constructor "+e);

}

gui=new StoreGui();

//向图形界面注册监听器

gui.addSelectionPanelListeners(selectionPanelListeners);

gui.addCustPanelListeners(custPanelListeners);

}

/** 注册控制器*/

public void addUserGestureListener(StoreController b)

throws StoreException,RemoteException{

storeControllers.add(b);

}

/** 在图形界面上展示参数display指定的数据 */

public void showDisplay(Object display) throws StoreException,RemoteException{

if(!(display instanceof Exception))this.display=display;

if(display instanceof Customer){

gui.refreshCustPane((Customer)display);

}

if(display instanceof Set){

gui.refreshAllCustPan((Set)display);

}

if(display instanceof Exception){

gui.updateLog(((Exception)display).getMessage());

}

}

/** 刷新界面上的客户信息*/

public void handleCustomerChange(Customer cust)throws StoreException,RemoteException{

long cIdOnPan=-1;

try{

if(display instanceof Set){

gui.refreshAllCustPan(storemodel.getAllCustomers());

return;

}

if(display instanceof Customer){

cIdOnPan=gui.getCustIdOnCustPan();

if(cIdOnPan!=cust.getId())return;

gui.refreshCustPane(cust);

}

}catch(Exception e){

System.out.println("StoreViewImpl processCustomer "+e);

}

}

/** 监听图形界面上【查询客户】按钮的ActionEvent的监听器 */

transient ActionListener custGetHandler=new ActionListener(){

public void actionPerformed(ActionEvent e){

StoreController sc;

long custId;

custId=gui.getCustIdOnCustPan();

for(int i=0;isc=storeControllers.get(i);

sc.handleGetCustomerGesture(custId);

}

}

};

/** 监听图形界面上【添加客户】按钮的ActionEvent的监听器 */

transient ActionListener custAddHandler=new ActionListener(){…};

/** 监听图形界面上【删除客户】按钮的ActionEvent的监听器 */

transient ActionListener custDeleteHandler=new ActionListener(){…};

/** 监听图形界面上【更新客户】按钮的ActionEvent的监听器 */

transient ActionListener custUpdateHandler=new ActionListener(){…};

/** 监听图形界面上【客户详细信息】按钮的ActionEvent的监听器 */

transient ActionListener custDetailsPageHandler=new ActionListener(){

public void actionPerformed(ActionEvent e){

StoreController sc;

long custId;

custId=gui.getCustIdOnCustPan();

if(custId==-1){

try{

showDisplay(new Customer(-1));

}catch(Exception ex){ex.printStackTrace();}

}else{

for(int i=0;isc=storeControllers.get(i);

sc.handleGetCustomerGesture(custId);

}

}

}

};

/** 监听图形界面上【所有客户清单】按钮的ActionEvent的监听器 */

transient ActionListener allCustsPageHandler=new ActionListener(){…};

/** 负责监听单个客户面板custPan上的所有按钮的ActionEvent事件的监听器 */

transient ActionListener custPanelListeners[] ={custGetHandler,custAddHandler,

custDeleteHandler,custUpdateHandler};

/** 负责监听选择面板selPan上的所有按钮的ActionEvent事件的监听器 */

transient ActionListener selectionPanelListeners[]={

custDetailsPageHandler,allCustsPageHandler};

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值