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

📄 ebank3.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="wp79946"> </a><div class="pSmartList1"><li><code class="cCode">resetPanelTwo</code>: Resets the right panel when the user selects OK to signal the end of a data view or update operation</li></div><a name="wp79947"> </a><div class="pSmartList1"><li><code class="cCode">createPanelTwoActLabels</code>: Creates labels for account fields when account information is either viewed or updated</li></div><a name="wp79948"> </a><div class="pSmartList1"><li><code class="cCode">createActFields</code>: Creates account fields when account information is either viewed or updated</li></div><a name="wp79949"> </a><div class="pSmartList1"><li><code class="cCode">createPanelTwoCustLabels</code>: Creates labels for customer fields when customer information is either viewed or updated</li></div><a name="wp79950"> </a><div class="pSmartList1"><li><code class="cCode">createCustFields</code>: Creates customer fields when customer information is either viewed or updated</li></div><a name="wp79951"> </a><div class="pSmartList1"><li><code class="cCode">addCustToActFields</code>: Creates labels and fields for when an add customer to account operation is invoked</li></div><a name="wp79952"> </a><div class="pSmartList1"><li><code class="cCode">makeRadioButtons</code>: Makes radio buttons for selecting the account type when a new account is created</li></div><a name="wp79953"> </a><div class="pSmartList1"><li><code class="cCode">getDescription</code>: Makes the radio button labels that describe each available account type</li></div></ul></div><a name="wp79955"> </a><h3 class="pHeading2">EventHandle Class</h3><a name="wp79957"> </a><p class="pBody">The <code class="cCode"><a  href="../bank/src/com/sun/ebank/appclient/EventHandle.java" target="_blank">EventHandle</a></code> class implements the <code class="cCode">ActionListener</code> interface, which provides a method interface for handling action events. Like all other interfaces in the Java programming language, <code class="cCode">ActionListener</code> defines a set of methods, but does not implement their behavior. Instead, you provide the implementations because they take application-specific actions. </p><a name="wp79958"> </a><h4 class="pHeading3">Constructor</h4><a name="wp79959"> </a><p class="pBody">The constructor receives an instance of the <code class="cCode">ResourceBundle</code> and <code class="cCode">BankAdmin</code> classes and assigns them to its private instance variable so that the <code class="cCode">EventHandle</code> object has access to the application client's localized text and can update the user interface as needed. Lastly, the constructor calls the <code class="cCode">hookupEvents</code> method to create the inner classes to listen for and handle action events.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public EventHandle(BankAdmin frame, ResourceBundle messages) {&nbsp;&nbsp; this.frame = frame;&nbsp;&nbsp; this.messages = messages;&nbsp;&nbsp; this.dataModel = new DataModel(frame, messages);&nbsp;&nbsp; //Hook up action events&nbsp;&nbsp; hookupEvents();}<a name="wp79960"> </a></pre></div><a name="wp79961"> </a><h4 class="pHeading3">actionPerformed Method</h4><a name="wp79962"> </a><p class="pBody">The <code class="cCode">ActionListener</code> interface has only one method, the <code class="cCode">actionPerformed</code> method. This method handles action events generated by the <code class="cCode">BankAdmin</code> user interface when users create a new account. Specifically, it sets the account description when a bank administrator selects an account type radio button and sets the current balance to the beginning balance for new accounts when a bank administrator presses the Return key in the Beginning Balance field.</p><a name="wp79963"> </a><h4 class="pHeading3">hookupEvents Method</h4><a name="wp79964"> </a><p class="pBody">The <code class="cCode">hookupEvents</code> method uses inner classes to handle menu and button press events. An inner class is a class nested or defined inside another class. Using inner classes in this way modularizes the code, making it easier to read and maintain. <code class="cCode">EventHandle</code> inner classes manage the following application client operations:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79965"> </a><div class="pSmartList1"><li>View customer information</li></div><a name="wp79966"> </a><div class="pSmartList1"><li>Create new customer</li></div><a name="wp79967"> </a><div class="pSmartList1"><li>Update customer information</li></div><a name="wp79968"> </a><div class="pSmartList1"><li>Find customer ID by last name</li></div><a name="wp79969"> </a><div class="pSmartList1"><li>View account information</li></div><a name="wp79970"> </a><div class="pSmartList1"><li>Create new account</li></div><a name="wp79971"> </a><div class="pSmartList1"><li>Add customer to account</li></div><a name="wp79972"> </a><div class="pSmartList1"><li>Remove account</li></div><a name="wp79973"> </a><div class="pSmartList1"><li>Clear data on Cancel button press</li></div><a name="wp79974"> </a><div class="pSmartList1"><li>Process data on OK button press</li></div></ul></div><a name="wp79976"> </a><h3 class="pHeading2">DataModel Class</h3><a name="wp79978"> </a><p class="pBody">The <code class="cCode"><a  href="../bank/src/com/sun/ebank/appclient/DataModel.java" target="_blank">DataModel</a></code> class provides methods for reading data from the database, writing data to the database, retrieving data from the user interface, and checking that data before it is written to the database.</p><a name="wp79979"> </a><h4 class="pHeading3">Constructor</h4><a name="wp79980"> </a><p class="pBody">The constructor receives an instance of the <code class="cCode">BankAdmin</code> class and assigns it to its private instance variable so that the <code class="cCode">DataModel</code> object can display error messages in the user interface when its <code class="cCode">checkActData</code>, <code class="cCode">checkCustData</code>, or <code class="cCode">writeData</code> method detects errors. It also receives an instance of the <code class="cCode">ResourceBundle</code> class and assigns it to its private instance variable so that the <code class="cCode">DataModel</code> object has access to the application client's localized text.</p><a name="wp79981"> </a><p class="pBody">Because the <code class="cCode">DataModel</code> class interacts with the database, the constructor also has the code to establish connections with the remote interfaces for the <code class="cCode">CustomerController</code> and <code class="cCode">AccountController</code> enterprise beans, and to use their remote interfaces to create instances of the <code class="cCode">CustomerController</code> and <code class="cCode">AccountController</code> enterprise beans.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">//Constructorpublic DataModel(BankAdmin frame, ResourceBundle messages) {&nbsp;&nbsp;this.frame = frame;&nbsp;&nbsp;this.messages = messages;//Look up and create CustomerController bean&nbsp;&nbsp;try {&nbsp;&nbsp;&nbsp;&nbsp;CustomerControllerHome customerControllerHome =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EJBGetter.getCustomerControllerHome();&nbsp;&nbsp;&nbsp;&nbsp;customer = customerControllerHome.create();&nbsp;&nbsp;} catch (Exception namingException) {&nbsp;&nbsp;&nbsp;&nbsp;namingException.printStackTrace();&nbsp;&nbsp;}//Look up and create AccountController bean&nbsp;&nbsp;try {&nbsp;&nbsp;&nbsp;&nbsp;AccountControllerHome accountControllerHome = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EJBGetter.getAccountControllerHome();&nbsp;&nbsp;&nbsp;&nbsp;account = accountControllerHome.create();&nbsp;&nbsp;} catch (Exception namingException) {&nbsp;&nbsp;&nbsp;&nbsp;namingException.printStackTrace();&nbsp;&nbsp;}}<a name="wp79982"> </a></pre></div><a name="wp79983"> </a><h4 class="pHeading3">Methods</h4><a name="wp79984"> </a><p class="pBody">The <code class="cCode">getData</code> method retrieves data from the user interface text fields and uses the <code class="cCode">String.trim</code> method to remove extra control characters such as spaces and returns. Its one parameter is a <code class="cCode">JTextfield</code> so that any instance of the <code class="cCode">JTextfield</code> class can be passed in for processing.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">private String getData(JTextField component) {&nbsp;&nbsp; String text, trimmed;&nbsp;&nbsp; if(component.getText().length() &gt; 0) {&nbsp;&nbsp;&nbsp;&nbsp;text = component.getText();&nbsp;&nbsp;&nbsp;&nbsp;trimmed = text.trim();&nbsp;&nbsp;&nbsp;&nbsp;return trimmed;&nbsp;&nbsp;} else {&nbsp;&nbsp;&nbsp;&nbsp;text = null;&nbsp;&nbsp;&nbsp;&nbsp;return text;&nbsp;&nbsp;}}<a name="wp79985"> </a></pre></div><a name="wp79986"> </a><p class="pBody">The <code class="cCode">checkCustData</code> method stores customer data retrieved by the <code class="cCode">getData</code> method, but first checks the data to be sure all required fields have data, the middle initial is no longer than one character, and the state is no longer than two characters. If everything checks out, the <code class="cCode">writeData</code> method is called. If there are errors, they are printed to the user interface in the <code class="cCode">BankAdmin</code> object. The <code class="cCode">checkActData</code> method uses a similar model to check and store account data.</p><a name="wp79987"> </a><p class="pBody">The <code class="cCode">createCustInf</code> and <code class="cCode">createActInf</code> methods are called by the <code class="cCode">EventHandle</code> class to refresh the Panel 2 display in the event of a view, update, or add action event. </p><a name="wp79988"> </a><p class="pDefinitionTerm">Create Customer Information</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79989"> </a><div class="pSmartList1"><li>For a view or update event, the <code class="cCode">createCustInf</code> method gets the customer information for the specified customer from the database and passes it to the <code class="cCode">createCustFields</code> method in the <code class="cCode">BankAdmin</code> class. A Boolean variable is used to determine whether the <code class="cCode">createCustFields</code> method should create read-only fields for a view event or writable fields for an update event.</li></div><a name="wp79990"> </a><div class="pSmartList1"><li>For a create event, the <code class="cCode">createCustInf</code> method calls the <code class="cCode">createCustFields</code> method in the <code class="cCode">BankAdmin</code> class with null data and a Boolean variable to create empty editable fields for the user to enter customer data.</li></div></ul></div><a name="wp79991"> </a><p class="pDefinitionTerm">Create Account Information</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79992"> </a><div class="pSmartList1"><li>For a view or update event, the <code class="cCode">createActInf</code> method gets the account information for the specified account from the database and passes it to the <code class="cCode">createActFields</code> method in the <code class="cCode">BankAdmin</code> class. A Boolean variable is used to determine whether the <code class="cCode">createActFields</code> method should create read-only fields for a view event or writable fields for an update event.</li></div><a name="wp79993"> </a><div class="pSmartList1"><li>For a create event, the <code class="cCode">createActInf</code> method calls the <code class="cCode">createActFields</code> method in the <code class="cCode">BankAdmin</code> class with null data and a Boolean variable to create empty editable fields for the user to enter customer data.</li></div><a name="wp79994"> </a><div class="pSmartList1"><li>Adding a customer to an account or removing an account events operate directly on the database without creating any user interface components.</li></div></ul></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <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"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

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