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

📄 brokercontrollerimpl.java

📁 java写的股票交易系统
💻 JAVA
字号:
package trader;
public class BrokerControllerImpl implements BrokerController {
  private BrokerModel brokerModel;
  private BrokerView brokerView;

  /** Creates new BrokerControllerImpl */
  public BrokerControllerImpl(BrokerModel model, BrokerView view) {
    try {
      //** 1 Assign model to brokerModel
      brokerModel = model;
      //** 2 Assign view to brokerView
      brokerView = view;
      //** 3 Register this object as a user gesture listener with
      //**   the brokerView object
      //**   Hint - invoke addUserGestureListener
      brokerView.addUserGestureListener(this);    
    } catch(Exception e) {
      reportException(e);
    }
  }

  private void reportException(Object o) {
    // The responsibility of this method is to report exceptions
    // It class the brokerView's showDisplay method
    try {
      brokerView.showDisplay(o);
    } catch(Exception e) {
      System.out.println("BrokerControllerImpl reportException " + e);
    }
  }
    
//user gesture call back methods
  /* ---------------------------------------------------------------
   * get customer user gesture handle method called by the broker
   * view in response to the get customer button click on the GUI or
   * equivalent user interface.
   * action - set customer display on the gui through the 
   * showDisplay method of the broker view
   */
   
        //modified by ourteam 051228
        //begin
       
 /* public void handleGetCustomerGesture(String id) {
   System.out.println("handleGetCustomerGesture " + id);
    Customer cust = null;
    try {
      //** 1 Set cust to the object returned as a result of
      //**   invoking the getCustomer method on brokerModel
      cust = brokerModel.getCustomer(id);
      //** 2 Invoke showDisplay method of brokerView with cust 
      //**   as parameter
      brokerView.showDisplay(cust);
    } catch(Exception e) {
      reportException(e);
      cust = new Customer(id);
      try {
        brokerView.showDisplay(cust);
      } catch (Exception ex) {
        reportException(ex);
      }
    }
  }*/
 
  public void handleGetCustomerGesture(String id, String name,String addr) {
    System.out.println("handleGetCustomerGesture " + id + ", " + name+","+addr);
    Customer cust = null;
    try {
      //** 1 Set cust to the object returned as a result of
      //**   invoking the getCustomer method on brokerModel
      cust = brokerModel.getCustomer(id, name,addr);
      //** 2 Invoke showDisplay method of brokerView with cust 
      //**   as parameter
      brokerView.showDisplay(cust);
    } catch(Exception e) {
      reportException(e);
      cust = new Customer(id);
      try {
        brokerView.showDisplay(cust);
      } catch (Exception ex) {
        reportException(ex);
      }
    }
  }
 
  
  /* ---------------------------------------------------------------
   * add new customer user gesture handle method called by the
   * broker view in response to the add customer button click on the
   * GUI or equivalent user interface.
   * action - add the (new) customer customer to the model
   */
  public void handleAddCustomerGesture(Customer c) {
    System.out.println("handleAddCustomerGesture " + c);
    try {
      //** 1 Invoke addCustomer method of brokerModel with c
      //**   as parameter
      brokerModel.addCustomer(c);
    } catch(Exception e) {
      reportException(e);
    }
  }
  
  /* ---------------------------------------------------------------
   * delete customer user gesture  handle method called by
   * the broker view in response to the delete customer 
   * button click on the GUI or equivalent user interface
   * action  - delete the customer from the model
   */
  public void handleDeleteCustomerGesture(Customer c){
    System.out.println("handleDeleteCustomerGesture " + c);
    try {
      //** 1 Invoke deleteCustomer method of brokerModel with c
      //**   as parameter
      brokerModel.deleteCustomer(c);
    } catch(Exception e) {
      reportException(e);
    }
  }
  
  /* ---------------------------------------------------------------
   * update customer user gesture callback method called by
   * the broker view in response to the update customer 
   * button click on the GUI or equivalent user interface
   * action  - update the customer in the model
   */
  public void handleUpdateCustomerGesture(Customer c){
    System.out.println("handleUpdateCustomerGesture " + c);
    try {
      //** 1 Invoke updateCustomer method of brokerModel with c
      //**   as parameter
      brokerModel.updateCustomer(c);
    } catch(Exception e) {
      reportException(e);
    }
  }
  
  /* ---------------------------------------------------------------
    * get all customers user gesture callback method called
    * the broker view in response to the get all customers 
    * button click on the GUI or equivalent user interface
    * action - set all customers display on the gui through the
    * showDisplay method of the broker view
    */
  public void handleGetAllCustomersGesture(){
    System.out.println("handleGetAllCustomersGesture ");
    Customer custs[];
    try {
      //** 1 Invoke getAllCustomers method of brokerModel
      //**   Assign the return value from this method to custs
      custs = brokerModel.getAllCustomers();
      //** 2 Invoke showDisplay method of brokerView with custs
      //** as parameter
      brokerView.showDisplay(custs);      
    } catch(Exception e) {
      reportException(e);
    }
  } 
  
  /* ---------------------------------------------------------------
    * get stocks user gesture callback method called
    * the broker view in response to the get all customers 
    * button click on the GUI or equivalent user interface
    * action - set all customers display on the gui through the
    * showDisplay method of the broker view
    */
  public void handleGetStockGesture(String symbol,String price){
    System.out.println("handleGetStockGesture "+symbol+" , "+price);
    Stock stock=null;
    try {
      stock = brokerModel.getStock(symbol, price);
      //** 2 Invoke showDisplay method of brokerView with stocks
      //** as parameter
      brokerView.showDisplay(stock);      
    } catch(Exception e) {
      reportException(e);
      stock = new Stock(symbol);
      try {
        brokerView.showDisplay(stock);
      } catch (Exception ex) {
        reportException(ex);
    }
  }

}

//modified  by  ourteam 051228
//begin
public void handleGetAllStocksGesture(){
    System.out.println("handleGetAllStocksGesture ");
    Stock stocks[];
    try {
      //** 1 Invoke  method of brokerModel
      //**   Assign if return value from this method to custs
      stocks = brokerModel.getAllStocks();
      //** 2 Invoke showDisplay method of brokerView with custs
      //** as parameter
      brokerView.showDisplay(stocks);      
    } catch(Exception e) {
      reportException(e);
    }
  } 
  
  //modified  by  ourteam 051228
  //begin
  public void handleGetPortfolioGesture(String id,String name,Share[] shares){
	System.out.println("handleGetPortfolioGesture " + id + ", " + name);
    Portfolio port = null;
    try {
      //** 1 Set cust to the object returned as a result of
      //**   invoking the getCustomer method on brokerModel
      port = brokerModel.getPortfolio(id,name,shares);
      //** 2 Invoke showDisplay method of brokerView with cust 
      //**   as parameter
      brokerView.showDisplay(port);
    } catch(Exception e) {
      reportException(e);
      port = new Portfolio(new Customer(id));
      try {
        brokerView.showDisplay(port);
      } catch (Exception ex) {
        reportException(ex);
      }
    }
  }
  
  public void handleAddPortfolioGesture(Portfolio p) {
    System.out.println("handleAddPortfolioGesture " + p);
    try {
      //** 1 Invoke addCustomer method of brokerModel with c
      //**   as parameter
      brokerModel.addPortfolio(p);
    } catch(Exception e) {
      reportException(e);
    }
  }
  
  /* ---------------------------------------------------------------
   * delete customer user gesture  handle method called by
   * the broker view in response to the delete customer 
   * button click on the GUI or equivalent user interface
   * action  - delete the customer from the model
   */
  public void handleDeletePortfolioGesture(Portfolio p){
    System.out.println("handleDeletePortfolioGesture " + p);
    try {
      //** 1 Invoke deleteCustomer method of brokerModel with c
      //**   as parameter
      brokerModel.deletePortfolio(p);
    } catch(Exception e) {
      reportException(e);
    }
  }
//end

  /*public void handleGetStockGesture(String symbol,String price) {
    System.out.println("handleGetCustomerGesture " + symbol + ", " +price);
    Stock stock=null;
    try {
      //** 1 Set cust to the object returned as a result of
      //**   invoking the getCustomer method on brokerModel
     stock = brokerModel.getStock(symbol, price);
      //** 2 Invoke showDisplay method of brokerView with cust 
      //**   as parameter
      brokerView.showDisplay(stock);
    } catch(Exception e) {
      reportException(e);
      stock= new Stock(symbol);
      try {
        brokerView.showDisplay(stock);
      } catch (Exception ex) {
        reportException(ex);
      }
    }
}*/
}

⌨️ 快捷键说明

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