📄 ebank3.html
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>Application Client</title> <link rel="StyleSheet" href="document.css" type="text/css" media="all" /> <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" /> <link rel="Table of Contents" href="J2EETutorialTOC.html" /> <link rel="Previous" href="Ebank2.html" /> <link rel="Next" href="Ebank4.html" /> <link rel="Index" href="J2EETutorialIX.html" /> </head> <body> <table width="550" summary="layout" id="SummaryNotReq1"> <tr> <td align="left" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a> </td> <td align="center" valign="center"><a accesskey="p" href="Ebank2.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="Ebank4.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a> </td> <td align="right" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font> </font> </td> </tr> </table> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <blockquote><a name="wp79892"> </a><h2 class="pHeading1">Application Client</h2><a name="wp79893"> </a><p class="pBody">Sometimes, enterprise applications use a stand-alone client application for handling tasks such as system or application administration. For example, the Duke's Bank application uses a J2EE application client to administer customers and accounts. This capability is useful in the event the site becomes inaccessible for any reason or a customer prefers to communicate things such as changes to account information by phone. </p><a name="wp79895"> </a><p class="pBody">A J2EE application client is a standalone program launched from the command line or desktop; it accesses enterprise beans running on the J2EE application server. </p><a name="wp79899"> </a><p class="pBody">The application client shown in <a href="Ebank3.html#wp79905">Figure 32-5</a> handles basic customer and account administration for the banking application through a Swing user interface. The bank administrator can perform any of the following functions by making menu selections.</p><a name="wp84482"> </a><p class="pBody"></p><div align="left"><img src="images/Fig414.gif" height="202" width="447" alt="Duke's Bank Application Client" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><a name="wp79903"> </a><p class="pBody"></p><p> <a name="79905"> </a><strong><font >Figure 32-5 Application Client</font></strong></p><a name="wp79906"> </a><p class="pBody">Customer Administration</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79907"> </a><div class="pSmartList1"><li>View customer information</li></div><a name="wp79908"> </a><div class="pSmartList1"><li>Add a new customer to the database </li></div><a name="wp79909"> </a><div class="pSmartList1"><li>Update customer information</li></div><a name="wp79910"> </a><div class="pSmartList1"><li>Find customer ID</li></div></ul></div><a name="wp79911"> </a><p class="pBody">Account Administration</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79912"> </a><div class="pSmartList1"><li>Create a new account</li></div><a name="wp79913"> </a><div class="pSmartList1"><li>Add a new customer to an existing account</li></div><a name="wp79914"> </a><div class="pSmartList1"><li>View account information</li></div><a name="wp79915"> </a><div class="pSmartList1"><li>Remove an account from the database</li></div></ul></div><a name="wp79916"> </a><p class="pBody">Error and informational messages appear in the left pane under <code class="cCode">Application message watch:</code>, and data is entered and displayed in the right pane.</p><a name="wp79918"> </a><h3 class="pHeading2">The Classes and Their Relationships</h3><a name="wp79920"> </a><p class="pBody">The source code for the application client is in the <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/bank/src/com/sun/ebank/appclient/</code> directory. The J2EE application client is divided into three classes: <code class="cCode">BankAdmin</code>, <code class="cCode">EventHandle</code>, and <code class="cCode">DataModel</code>; the relationships among the classes are depicted in <a href="Ebank3.html#wp79929">Figure 32-6</a>.</p><a name="wp84464"> </a><p class="pBody"></p><div align="left"><img src="images/Fig425.gif" height="364" width="362" alt="Application Client Class Relationships" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><a name="wp79927"> </a><p class="pBody"></p><p> <a name="79929"> </a><strong><font >Figure 32-6 Relationships among Classes</font></strong></p><a name="wp79930"> </a><p class="pBody"><code class="cCode">BankAdmin</code> builds the initial user interface, creates the <code class="cCode">EventHandle</code> object, and provides methods for the <code class="cCode">EventHandle</code> and <code class="cCode">DataModel</code> objects to call to update the user interface. </p><a name="wp79931"> </a><p class="pBody"><code class="cCode">EventHandle</code> listens for button clicks by the user, takes action based on which button the user clicks, creates the <code class="cCode">DataModel</code> object, calls methods in the <code class="cCode">DataModel</code> object to write data to and read data from the enterprise beans, and calls methods in the <code class="cCode">BankAdmin</code> object to update the user interface when actions complete. </p><a name="wp79932"> </a><p class="pBody"><code class="cCode">DataModel</code> retrieves data from the user interface, performs data checks, writes valid data to and reads stored data from the underlying database, and calls methods in the <code class="cCode">BankAdmin</code> object to update the user interface based on the success of the database read or write operation. </p><a name="wp79934"> </a><h3 class="pHeading2">BankAdmin Class</h3><a name="wp79937"> </a><p class="pBody">The <code class="cCode"><a href="../bank/src/com/sun/ebank/appclient/BankAdmin.java" target="_blank">BankAdmin</a></code> class, which creates the user interface, is the class with the <code class="cCode">main</code> method, and provides <code class="cCode">protected</code> methods for the other <code class="cCode">BankAdmin</code> application classes to call. </p><a name="wp79938"> </a><h4 class="pHeading3">main Method</h4><a name="wp79939"> </a><p class="pBody">The <code class="cCode">main</code> method creates instances of the <code class="cCode">BankAdmin</code> and <code class="cCode">EventHandle</code> classes. Arguments passed to the <code class="cCode">main</code> method are used to initialize a locale, which is passed to the <code class="cCode">BankAdmin</code> constructor. </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public static void main(String args[]) { String language, country; if(args.length == 1) { language = new String(args[0]); currentLocale = new Locale(language, ""); } else if(args.length == 2) { language = new String(args[0]); country = new String(args[1]); currentLocale = new Locale(language, country); } else currentLocale = Locale.getDefault(); frame = new BankAdmin(currentLocale); frame.setTitle(messages.getString( "CustAndAccountAdmin")); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; frame.addWindowListener(l); frame.pack(); frame.setVisible(true); ehandle = new EventHandle(frame, messages); System.exit(0); }}<a name="wp79940"> </a></pre></div><a name="wp79941"> </a><h4 class="pHeading3">Constructor</h4><a name="wp79942"> </a><p class="pBody">The <code class="cCode">BankAdmin</code> constructor creates the initial user interface, which consists of a menu bar and two panels. The menu bar contains the customer and account menus, the left panel contains a message area, and the right panel is a data display or update area. </p><a name="wp79943"> </a><h4 class="pHeading3">Class Methods</h4><a name="wp79944"> </a><p class="pBody">The <code class="cCode">BankAdmin</code> class provides methods that other objects call when they need to update the user interface. These methods are as follows:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79945"> </a><div class="pSmartList1"><li><code class="cCode">clearMessages</code>: Clears the application messages that appear in the left panel</li></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -