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

📄 ch14.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TT>714:             currentBalanceTextField.setText(&quot;&quot;);</TT><TT>715:             transactionTextField.setText(&quot;&quot;);</TT><TT>716:         }</TT><TT>717:     }</TT><TT>718: </TT><TT>719:     /**</TT><TT>720:      * Update the Account information to correspond to the</TT><TT>721:      * currently selected Account.</TT><TT>722:      */</TT><TT>723:     protected void updateAccountInfo() {</TT><TT>724: </TT><TT>725:         if (mySelectedAccount == null) {</TT><TT>726:             return;</TT><TT>727:         }</TT><TT>728: </TT><TT>729:         issuingBankTextField.setText(((Bank)myAccountBankMap.</TT><TT>730:                 get(mySelectedAccount)).name());</TT><TT>731:         accountNumberTextField.setText(mySelectedAccount.</TT><TT>732:                 accountNumber());</TT><TT>733:         if (CheckingAccountHelper.narrow(mySelectedAccount) !=</TT><TT>734:                 null) {</TT><TT>735:             accountTypeTextField.setText(&quot;Checking&quot;);</TT><TT>736:         } else {</TT><TT>737: </TT><TT>738:             // If Account is not a CheckingAccount, assume it is a</TT><TT>739:             // SavingsAccount</TT><TT>740:             accountTypeTextField.setText(&quot;Savings&quot;);</TT><TT>741:         }</TT><TT>742:         creationDateTextField.setText(mySelectedAccount.</TT><TT>743:                 creationDate());</TT><TT>744:         currentBalanceTextField.setText(String.</TT><TT>745:                 valueOf(mySelectedAccount.balance()));</TT><TT>746:     }</TT><TT>747: </TT><TT>748:     class SymAction implements java.awt.event.ActionListener {</TT><TT>749: </TT><TT>750:         public void actionPerformed(java.awt.event.ActionEvent</TT><TT>751:                 event) {</TT><TT>752:             Object object = event.getSource();</TT><TT>753:             if (object == newCustomerButton)</TT><TT>754:                 newCustomerButton_Action(event);</TT><TT>755:             else if (object == newAccountButton)</TT><TT>756:                 newAccountButton_Action(event);</TT><TT>757:             else if (object == autoUpdateButton)</TT><TT>758:                 autoUpdateButton_Action(event);</TT><TT>759:             else if (object == depositButton)</TT><TT>760:                 depositButton_Action(event);</TT><TT>761:             else if (object == withdrawButton)</TT><TT>762:                 withdrawButton_Action(event);</TT><TT>763:             else if (object == updateAccountButton)</TT><TT>764:                 updateAccountButton_Action(event);</TT><TT>765:         }</TT><TT>766:     }</TT><TT>767: </TT><TT>768:     void newCustomerButton_Action(java.awt.event.ActionEvent event)</TT><TT>769:             {</TT><TT>770: </TT><TT>771:         Container theFrame = this;</TT><TT>772:         do {</TT><TT>773:             theFrame = theFrame.getParent();</TT><TT>774:         } while ((theFrame != null) &amp;&amp; !(theFrame instanceof</TT><TT>775:                 Frame));</TT><TT>776:         if (theFrame == null)</TT><TT>777:             theFrame = new Frame();</TT><TT>778: </TT><TT>779:         CustomerDialog cd = new CustomerDialog((Frame)theFrame,</TT><TT>780:                 true);</TT><TT>781:         cd.show();</TT><TT>782:         if (cd.myOKPressed) {</TT><TT>783:             createCustomer(cd.nameTextField.getText(), cd.</TT><TT>784:                     socialSecurityNumberTextField.getText(), cd.</TT><TT>785:                     addressTextField.getText(), cd.</TT><TT>786:                     mothersMaidenNameTextField.getText());</TT><TT>787:         }</TT><TT>788:     }</TT><TT>789: </TT><TT>790:     void newAccountButton_Action(java.awt.event.ActionEvent event)</TT><TT>791:             {</TT><TT>792: </TT><TT>793:         Container theFrame = this;</TT><TT>794:         do {</TT><TT>795:             theFrame = theFrame.getParent();</TT><TT>796:         } while ((theFrame != null) &amp;&amp; !(theFrame instanceof</TT><TT>797:                 Frame));</TT><TT>798:         if (theFrame == null)</TT><TT>799:             theFrame = new Frame();</TT><TT>800: </TT><TT>801:         AccountDialog ad = new AccountDialog((Frame)theFrame,</TT><TT>802:                 true);</TT><TT>803:         ad.show();</TT><TT>804:         if (ad.myOKPressed) {</TT><TT>805:             createAccount(mySelectedCustomer, ad.checkingRadio.</TT><TT>806:                     getState() ? &quot;checking&quot; : &quot;savings&quot;, new</TT><TT>807:                     Float(ad.initialBalanceTextField.getText()).</TT><TT>808:                     floatValue());</TT><TT>809:         }</TT><TT>810:     }</TT><TT>811: </TT><TT>812:     class SymItem implements java.awt.event.ItemListener {</TT><TT>813: </TT><TT>814:         public void itemStateChanged(java.awt.event.ItemEvent</TT><TT>815:                 event) {</TT><TT>816:             Object object = event.getSource();</TT><TT>817:             if (object == bankChoice)</TT><TT>818:                 bankChoice_ItemStateChanged(event);</TT><TT>819:             else if (object == atmChoice)</TT><TT>820:                 atmChoice_ItemStateChanged(event);</TT><TT>821:             else if (object == customerChoice)</TT><TT>822:                 customerChoice_ItemStateChanged(event);</TT><TT>823:             else if (object == accountChoice)</TT><TT>824:                 accountChoice_ItemStateChanged(event);</TT><TT>825:         }</TT><TT>826:     }</TT><TT>827: </TT><TT>828:     void bankChoice_ItemStateChanged(java.awt.event.ItemEvent</TT><TT>829:             event) {</TT><TT>830: </TT><TT>831:         if (event.getStateChange() == ItemEvent.SELECTED) {</TT><TT>832:             mySelectedBank = (Bank)myBanks.get(bankChoice.</TT><TT>833:                     getSelectedItem());</TT><TT>834:         }</TT><TT>835:     }</TT><TT>836: </TT><TT>837:     void atmChoice_ItemStateChanged(java.awt.event.ItemEvent event)</TT><TT>838:             {</TT><TT>839: </TT><TT>840:         if (event.getStateChange() == ItemEvent.SELECTED) {</TT><TT>841:             mySelectedATM = (ATM)myATMs.get(atmChoice.</TT><TT>842:                     getSelectedItem());</TT><TT>843:         }</TT><TT>844:     }</TT><TT>845: </TT><TT>846:     void customerChoice_ItemStateChanged(java.awt.event.ItemEvent</TT><TT>847:             event) {</TT><TT>848: </TT><TT>849:         if (event.getStateChange() == ItemEvent.SELECTED) {</TT><TT>850: </TT><TT>851:             // Update the Account list to show the currently</TT><TT>852:             // selected Customer's Accounts.</TT><TT>853:             mySelectedCustomer = (Customer)myCustomers.</TT><TT>854:                     get(customerChoice.getSelectedItem());</TT><TT>855:             accountChoice.removeAll();</TT><TT>856:             Hashtable accounts = (Hashtable)myAccounts.</TT><TT>857:                     get(mySelectedCustomer);</TT><TT>858:             if (accounts != null) {</TT><TT>859:                 Enumeration e = accounts.keys();</TT><TT>860:                 while (e.hasMoreElements()) {</TT><TT>861:                     accountChoice.add((String)e.nextElement());</TT><TT>862:                 }</TT><TT>863:             }</TT><TT>864:             mySelectedAccount = null;</TT><TT>865:             enableAccountFeatures(false);</TT><TT>866:         }</TT><TT>867:     }</TT><TT>868: </TT><TT>869:     void accountChoice_ItemStateChanged(java.awt.event.ItemEvent</TT><TT>870:             event) {</TT><TT>871: </TT><TT>872:         if (event.getStateChange() == ItemEvent.SELECTED) {</TT><TT>873:             Hashtable accounts = (Hashtable)myAccounts.</TT><TT>874:                     get(mySelectedCustomer);</TT><TT>875:             mySelectedAccount = (Account)accounts.</TT><TT>876:                     get(accountChoice.getSelectedItem());</TT><TT>877:             enableAccountFeatures(true);</TT><TT>878:             updateAccountInfo();</TT><TT>879:         }</TT><TT>880:     }</TT><TT>881: </TT><TT>882:     void autoUpdateButton_Action(java.awt.event.ActionEvent event)</TT><TT>883:             {</TT><TT>884: </TT><TT>885:         setStatus(&quot;Requesting AutoUpdate service for selected &quot; +</TT><TT>886:                 &quot;Account...&quot;);</TT><TT>887:         try {</TT><TT>888:             ((Bank)myAccountBankMap.get(mySelectedAccount)).</TT><TT>889:                     requestUpdateService(mySelectedAccount);</TT><TT>890:         } catch (InvalidAccountException ex) {</TT><TT>891:             setStatus(&quot;Could not request AutoUpdate service for &quot; +</TT><TT>892:                     &quot;selected Account: InvalidAcccountException&quot;);</TT><TT>893:         }</TT><TT>894:         setStatus(null);</TT><TT>895:     }</TT><TT>896: </TT><TT>897:     void depositButton_Action(java.awt.event.ActionEvent event) {</TT><TT>898: </TT><TT>899:         String amount = transactionTextField.getText();</TT><TT>900:         setStatus(&quot;Depositing $&quot; + amount + &quot;...&quot;);</TT><TT>901:         float newBalance = 0.0f;</TT><TT>902:         try {</TT><TT>903:             newBalance = mySelectedAccount.deposit(new</TT><TT>904:                     Float(amount).floatValue());</TT><TT>905:         } catch (InvalidAmountException ex) {</TT><TT>906:             setStatus(&quot;Could not perform transaction: &quot; +</TT><TT>907:                     &quot;InvalidAmountException&quot;);</TT><TT>908:             return;</TT><TT>909:         } catch (NumberFormatException ex) {</TT><TT>910:             setStatus(&quot;Could not perform transaction: &quot; +</TT><TT>911:                     &quot;NumberFormatException&quot;);</TT><TT>912:             return;</TT><TT>913:         }</TT><TT>914:         currentBalanceTextField.setText(String.</TT><TT>915:                 valueOf(newBalance));</TT><TT>916:         setStatus(&quot;Deposited $&quot; + amount + &quot; into selected &quot; +</TT><TT>917:                 &quot;Account.&quot;);</TT><TT>918:     }</TT><TT>919: </TT><TT>920:     void withdrawButton_Action(java.awt.event.ActionEvent event) {</TT><TT>921: </TT><TT>922:         String amount = transactionTextField.getText();</TT><TT>923:         setStatus(&quot;Withdrawing $&quot; + amount + &quot;...&quot;);</TT><TT>924:         float newBalance = 0.0f;</TT><TT>925:         try {</TT><TT>926:             newBalance = mySelectedAccount.withdraw(new</TT><TT>927:                     Float(amount).floatValue());</TT><TT>928:         } catch (InvalidAmountException ex) {</TT><TT>929:             setStatus(&quot;Could not perform transaction: &quot; +</TT><TT>930:                     &quot;InvalidAmountException&quot;);</TT><TT>931:             return;</TT><TT>932:         } catch (InsufficientFundsException ex) {</TT><TT>933:             setStatus(&quot;Could not perform transaction: &quot; +</TT><TT>934:                     &quot;InsufficientFundsException&quot;);</TT><TT>935:             return;</TT><TT>936:         } catch (NumberFormatException ex) {</TT><TT>937:             setStatus(&quot;Could not perform transaction: &quot; +</TT><TT>938:                     &quot;NumberFormatException&quot;);</TT><TT>939:             return;</TT><TT>940:         }</TT><TT>941:         currentBalanceTextField.setText(String.</TT><TT>942:                 valueOf(newBalance));</TT><TT>943:         setStatus(&quot;Withdrew $&quot; + amount + &quot; from selected &quot; +</TT><TT>944:                 &quot;Account.&quot;);</TT><TT>945:     }</TT><TT>946: </TT><TT>947:     void updateAccountButton_Action(java.awt.event.ActionEvent</TT><TT>948:             event) {</TT><TT>949: </TT><TT>950:         updateAccountInfo();</TT><TT>951:     }952: }</TT> </FONT></PRE><P>Now take a look at selected portions of <TT>BankApplet.java</TT>. The three <TT>import</TT>statements in lines 3-5 import the definitions of several GUI-related Java classes.The <TT>java.awt</TT> package and related packages contain the classes and interfacesthat compose the Abstract Windowing Toolkit (AWT). The AWT is a collection of userinterface objects and the event handling mechanism that enables those objects tointeract with each other. Applications and libraries can build on the core AWT classesto create more complex user interface objects and entire user interfaces.</P><P>The <TT>java.util</TT> package includes a number of utility classes and interfaces.One interface is the <TT>Enumeration</TT> (imported in line 6), which enables theiteration across collections (such as <TT>Vector</TT>, <TT>Dictionary</TT>, <TT>Hashtable</TT>,and so on), much like a C++ Standard Template Library (STL) iterator. The <TT>Hashtable</TT>class (imported in line 7), as its name suggests, implements a <

⌨️ 快捷键说明

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