cartclient.java

来自「卡内基梅隆大学软件工程课件,很全面」· Java 代码 · 共 56 行

JAVA
56
字号
/* * * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. *  * This software is the proprietary information of Sun Microsystems, Inc.   * Use is subject to license terms. *  */import java.util.*;import javax.naming.Context;import javax.naming.InitialContext;import javax.rmi.PortableRemoteObject;public class CartClient {   public static void main(String[] args) {       try {           Context initial = new InitialContext();           Object objref = initial.lookup("java:comp/env/ejb/SimpleCart");           CartHome home =                (CartHome)PortableRemoteObject.narrow(objref,                                             CartHome.class);           Cart shoppingCart = home.create("Duke DeEarl","123");           shoppingCart.addBook("The Martian Chronicles");           shoppingCart.addBook("2001 A Space Odyssey");           shoppingCart.addBook("The Left Hand of Darkness");                      Vector bookList = new Vector();           bookList = shoppingCart.getContents();           Enumeration enumer = bookList.elements();           while (enumer.hasMoreElements()) {              String title = (String) enumer.nextElement();              System.out.println(title);           }           shoppingCart.removeBook("Alice in Wonderland");           shoppingCart.remove();           System.exit(0);       } catch (BookException ex) {           System.err.println("Caught a BookException: " + ex.getMessage());           System.exit(0);       } catch (Exception ex) {           System.err.println("Caught an unexpected exception!");           ex.printStackTrace();           System.exit(1);       }   } } 

⌨️ 快捷键说明

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