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

📄 ch14.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</HEAD>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//-->                                                                </SCRIPT>	<META NAME="Author" Content="Bryan Flores">	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">	<TITLE>Teach Yourself CORBA In 14 Days -- Ch 14 -- Web-Enabling the Bank Example with Java</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself CORBA In 14 Days</FONT></H1></CENTER><CENTER><P><A HREF="../ch13/ch13.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../apa/apa.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1><FONT COLOR="#000077">Day 14<BR>Web-Enabling the Bank Example with Java</FONT></H1></CENTER><UL>	<LI><A HREF="#Heading1">Developing the BankApplet</A>	<UL>		<LI><A HREF="#Heading2">Implementing the Server Functionality</A>		<LI><A HREF="#Heading3">Implementing the Client Functionality</A>	</UL>	<LI><A HREF="#Heading4">Running the Applet</A>	<UL>		<LI><A HREF="#Heading5">Using appletviewer</A>		<LI><A HREF="#Heading6">Using a Web Browser</A>	</UL>	<LI><A HREF="#Heading7">Summary</A>	<LI><A HREF="#Heading8">Q&amp;A</A>	<LI><A HREF="#Heading9">Workshop</A>	<UL>		<LI><A HREF="#Heading10">Quiz</A>		<LI><A HREF="#Heading11">Exercise</A>	</UL></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>On Day 13, &quot;Developing for the Internet Using CORBA and Java,&quot; you wereintroduced to the Java programming language and proceeded to port the <TT>Bank</TT>application from C++ to Java. The porting process was straightforward, due to thesimilarities between C++ and Java and the fact that you didn't add any new functionalityto the application when you ported it. The result was a CORBA application that behavedexactly like its predecessor, with no new bells or whistles.</P><P>Today, you'll take the Java version of the <TT>Bank</TT> example to its next logicalevolutionary step. One of Java's greater potentials is in the development of graphicaluser interfaces (GUIs), and in this chapter you'll explore Java's capabilities inthat area. Of course, the subject of developing GUIs in Java would by itself fillan entire book, so many of the details are omitted here. By the end of today, though,you will have built a functional Java applet that provides a GUI version of the functionalityformerly provided by the <TT>ATMClient</TT> portion of the <TT>Bank</TT> application.<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Developing the BankApplet</FONT></H2><P>The process for developing the applet varies slightly from processes in previouschapters, primarily due to the inclusion of a GUI interface instead of the previouscommand-line interfaces. Here is the process you'll follow this time around:<UL>	<LI>Implement the server functionality. As it turns out, you don't have to make any	changes to the existing server components.<BR>	<BR>		<LI>Implement the client functionality. You'll replace the former <TT>ATMClient</TT>	with a Java applet called, ever so originally, <TT>BankApplet</TT>.<BR>	<BR>		<LI>Deploy the <TT>BankApplet</TT>. You'll run the <TT>BankApplet</TT> in the <TT>appletviewer</TT>	(a standalone application that runs Java applets) and then in a Web browser.</UL><H3><A NAME="Heading2"></A><FONT COLOR="#000077">Implementing the Server Functionality</FONT></H3><P>As on Day 13, no changes will be made to the server components of the <TT>Bank</TT>application. When the time comes to run the sample application, you'll run the same<TT>BankServer</TT>, <TT>Bank</TT>, and <TT>ATM</TT> server components as on Day13.<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Implementing the Client Functionality</FONT></H3><P>Before delving into the development of the <TT>BankApplet</TT>, you need to makea slight modification to the existing <TT>CustomerImpl</TT>. The reason is that,until now, all output of the client application (and of the server applications,for that matter) has been to the system console (the <TT>cout</TT> stream in C++or the <TT>System.out</TT> stream in Java). Previously, the <TT>updateAccountBalance()</TT>method of <TT>CustomerImpl</TT> simply printed a message to <TT>System.out</TT>,which is fine for a console mode application such as the former <TT>ATMClient</TT>.However, for a graphical client application such as <TT>BankApplet</TT>, you probablywant to deal with messages in a more graphical way. You'll see how the <TT>BankApplet</TT>handles such messages, but for now, just recognize that the <TT>CustomerImpl</TT>forwards the update message to another object--one that implements the <TT>AccountUpdateListener</TT>interface (which you'll also see in a moment).<H4><FONT COLOR="#000077">Customer</FONT></H4><P>The modifications to the <TT>CustomerImpl</TT> class are very minor; the <TT>CustomerImpl</TT>constructor now accepts an <TT>AccountUpdateListener</TT> parameter, which is usedwhen account update messages are later sent to the <TT>CustomerImpl</TT>. Also, asmentioned previously, the <TT>updateAccountBalance()</TT> method itself, rather thanprint a message to <TT>System.out</TT>, now forwards the update message to the registered<TT>AccountUpdateListener</TT> object. (You'll soon see that the <TT>AccountUpdateListener</TT>object, in this case, is the <TT>BankApplet</TT> itself.) The modified <TT>CustomerImpl.java</TT>appears in Listing 14.1.<H4><FONT COLOR="#000077">Listing 14.1. CustomerImpl.java.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>  1: // CustomerImpl.java</TT><TT>  2: </TT><TT>  3: import java.util.Enumeration;</TT><TT>  4: import java.util.Vector;</TT><TT>  5: </TT><TT>  6: import idlGlobal.Account;</TT><TT>  7: </TT><TT>  8: public class CustomerImpl extends idlGlobal._CustomerImplBase {</TT><TT>  9: </TT><TT> 10:     // This Customer's name.</TT><TT> 11:     private String myName;</TT><TT> 12: </TT><TT> 13:     // This Customer's Social Security number.</TT><TT> 14:     private String mySocialSecurityNumber;</TT><TT> 15: </TT><TT> 16:     // This Customer's address.</TT><TT> 17:     private String myAddress;</TT><TT> 18: </TT><TT> 19:     // This Customer's mother's maiden name.</TT><TT> 20:     private String myMothersMaidenName;</TT><TT> 21: </TT><TT> 22:     // This Customer's list of Accounts.</TT><TT> 23:     private Vector myAccounts;</TT><TT> 24: </TT><TT> 25:     // This Customer's list of ATMCards.</TT><TT> 26:     private Vector myATMCards;</TT><TT> 27: </TT><B><TT> 28:     // This Customer's AccountUpdateListener (for simplicity, only</TT></B><B><TT> 29:     // one is allowed).</TT></B><B><TT> 30:     private AccountUpdateListener myAccountUpdateListener;</TT></B><TT> 31: </TT><TT> 32:     public CustomerImpl(String name, String socialSecurityNumber,</TT><TT> 33:             String address, String mothersMaidenName<B>,</B></TT><B><TT> 34:             AccountUpdateListener accountUpdateListener</TT></B><TT>) {</TT><TT> 35: </TT><TT> 36:             super(socialSecurityNumber);</TT><TT> 37: </TT><TT> 38:             myName = new String(name);</TT><TT> 39:             mySocialSecurityNumber = new</TT><TT> 40:                     String(socialSecurityNumber);</TT><TT> 41:             myAddress = new String(address);</TT><TT> 42:             myMothersMaidenName = new String(mothersMaidenName);</TT><TT> 43:             myAccounts = new Vector();</TT><TT> 44:             myATMCards = new Vector();</TT><B><TT> 45:             myAccountUpdateListener = accountUpdateListener;</TT></B><TT> 46:     }</TT><TT> 47: </TT><TT> 48:     protected CustomerImpl() {</TT><TT> 49: </TT><TT> 50:         myName = new String();</TT><TT> 51:         mySocialSecurityNumber = new String();</TT><TT> 52:         myAddress = new String();</TT><TT> 53:         myMothersMaidenName = new String();</TT><TT> 54:         myAccounts = new Vector();</TT><TT> 55:         myATMCards = new Vector();</TT><TT> 56:     }</TT><TT> 57: </TT><TT> 58:     public void name(String name) {</TT><TT> 59: </TT><TT> 60:         myName = new String(name);</TT><TT> 61:     }</TT><TT> 62: </TT><TT> 63:     public String name() {</TT><TT> 64: </TT><TT> 65:         return myName;</TT><TT> 66:     }</TT><TT> 67: </TT><TT> 68:     public String socialSecurityNumber() {</TT><TT> 69: </TT><TT> 70:         return mySocialSecurityNumber;</TT><TT> 71:     }</TT><TT> 72: </TT><TT> 73:     public void address(String address) {</TT><TT> 74: </TT><TT> 75:         myAddress = new String(address);</TT><TT> 76:     }</TT><TT> 77: </TT><TT> 78:     public String address() {</TT><TT> 79: </TT><TT> 80:         return myAddress;</TT><TT> 81:     }</TT><TT> 82: </TT><TT> 83:     public java.lang.String mothersMaidenName() {</TT><TT> 84: </TT><TT> 85:         return myMothersMaidenName;</TT><TT> 86:     }</TT><TT> 87: </TT><TT> 88:     public Account[] getAccounts() {</TT><TT> 89: </TT><TT> 90:         Account[] list = new Account[myAccounts.size()];</TT><TT> 91:         myAccounts.copyInto(list);</TT><TT> 92: </TT><TT> 93:         Enumeration e = myAccounts.elements();</TT><TT> 94:         while (e.hasMoreElements()) {</TT><TT> 95:             ((Account)e.nextElement())._duplicate();</TT><TT> 96:         }</TT><TT> 97: </TT><TT> 98:         return list;</TT><TT> 99:     }</TT><TT>100: </TT><TT>101:     public void updateAccountBalance(Account account, float</TT><TT>102:             balance) {</TT><TT>103: </TT><B><TT>104:         myAccountUpdateListener.update(account, balance);</TT></B><TT>105:     }106: }</TT> </FONT></PRE><P>The <TT>AccountUpdateListener</TT> interface is simple, its only purpose beingto accept update messages for <TT>Account</TT>s. Consequently, its single method,<TT>update()</TT>, reflects the <TT>updateAccountBalance()</TT> method in <TT>CustomerImpl</TT>.Note that, as an interface, <TT>AccountUpdateListener</TT> doesn't provide an implementationfor this method; the implementation is the responsibility of the class(es) implementingthis interface. <TT>AccountUpdateListener.java</TT> appears in Listing 14.2.<H4><FONT COLOR="#000077">Listing 14.2. AccountUpdateListener.java.</FONT></H4>

⌨️ 快捷键说明

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