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

📄 ch14.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TT>459:         statusTextField = new java.awt.TextField();</TT><TT>460:         statusTextField.setEditable(false);</TT><TT>461:         statusTextField.setText(&quot;BankApplet Ready.&quot;);</TT><TT>462:         statusTextField.setBounds(2, 302, 400, 23);</TT><TT>463:         gbc = new GridBagConstraints();</TT><TT>464:         gbc.gridx = 0;</TT><TT>465:         gbc.gridy = 5;</TT><TT>466:         gbc.gridwidth = 4;</TT><TT>467:         gbc.weightx = 1.0;</TT><TT>468:         gbc.anchor = GridBagConstraints.SOUTH;</TT><TT>469:         gbc.fill = GridBagConstraints.HORIZONTAL;</TT><TT>470:         gbc.insets = new Insets(2, 2, 2, 2);</TT><TT>471:         ((GridBagLayout)getLayout()).</TT><TT>472:                 setConstraints(statusTextField, gbc);</TT><TT>473:         add(statusTextField);</TT><TT>474:         //}}</TT><TT>475: </TT><TT>476:         //{{REGISTER_LISTENERS</TT><TT>477:         SymAction lSymAction = new SymAction();</TT><TT>478:         newCustomerButton.addActionListener(lSymAction);</TT><TT>479:         newAccountButton.addActionListener(lSymAction);</TT><TT>480:         SymItem lSymItem = new SymItem();</TT><TT>481:         bankChoice.addItemListener(lSymItem);</TT><TT>482:         atmChoice.addItemListener(lSymItem);</TT><TT>483:         customerChoice.addItemListener(lSymItem);</TT><TT>484:         accountChoice.addItemListener(lSymItem);</TT><TT>485:         autoUpdateButton.addActionListener(lSymAction);</TT><TT>486:         depositButton.addActionListener(lSymAction);</TT><TT>487:         withdrawButton.addActionListener(lSymAction);</TT><TT>488:         updateAccountButton.addActionListener(lSymAction);</TT><TT>489:         //}}</TT><TT>490: </TT><TT>491:         // Initialize the ORB and BOA.</TT><TT>492:         myORB = ORB.init(this);</TT><TT>493:         myBOA = myORB.BOA_init();</TT><TT>494: </TT><TT>495:         // Locate a BankServer object and try to get a list of</TT><TT>496:         // Banks and ATMs from it.</TT><TT>497:         setStatus(&quot;Binding to a BankServer...&quot;);</TT><TT>498:         try {</TT><TT>499:             myBankServer = BankServerHelper.bind(myORB);</TT><TT>500:         } catch (Exception ex) {</TT><TT>501: </TT><TT>502:             // The bind attempt failed...</TT><TT>503:             setStatus(&quot;Unable to bind to a BankServer.&quot;);</TT><TT>504:             System.out.println(ex);</TT><TT>505:             return;</TT><TT>506:         }</TT><TT>507:         setStatus(&quot;Successfully bound to a BankServer.&quot;);</TT><TT>508: </TT><TT>509:         // Get lists of Banks and ATMs from the BankServer.</TT><TT>510:         ATM[] atms;</TT><TT>511:         Bank[] banks;</TT><TT>512:         setStatus(&quot;Getting list of available Banks...&quot;);</TT><TT>513:         try {</TT><TT>514:             banks = myBankServer.getBanks();</TT><TT>515:         } catch (Exception ex) {</TT><TT>516: </TT><TT>517:             // The attempt failed...</TT><TT>518:             setStatus(&quot;Unable to get list of Banks.&quot;);</TT><TT>519:             return;</TT><TT>520:         }</TT><TT>521:         setStatus(&quot;Getting list of available ATMs...&quot;);</TT><TT>522:         try {</TT><TT>523:             atms = myBankServer.getATMs();</TT><TT>524:         } catch (Exception ex) {</TT><TT>525: </TT><TT>526:             // The attempt failed...</TT><TT>527:             setStatus(&quot;Unable to get list of ATMs.&quot;);</TT><TT>528:             return;</TT><TT>529:         }</TT><TT>530:         addBanks(banks);</TT><TT>531:         addATMs(atms);</TT><TT>532:         setStatus(null);</TT><TT>533:     }</TT><TT>534: </TT><TT>535:     //{{DECLARE_CONTROLS</TT><TT>536:     java.awt.Choice bankChoice;</TT><TT>537:     java.awt.Choice atmChoice;</TT><TT>538:     java.awt.Choice customerChoice;</TT><TT>539:     java.awt.Button newCustomerButton;</TT><TT>540:     java.awt.Choice accountChoice;</TT><TT>541:     java.awt.Button newAccountButton;</TT><TT>542:     java.awt.Button autoUpdateButton;</TT><TT>543:     java.awt.Label selectBankLabel;</TT><TT>544:     java.awt.Label selectATMLabel;</TT><TT>545:     java.awt.Label selectCustomerLabel;</TT><TT>546:     java.awt.Label selectAccountLabel;</TT><TT>547:     java.awt.Panel accountActionPanel;</TT><TT>548:     java.awt.Panel accountInfoPanel;</TT><TT>549:     java.awt.TextField issuingBankTextField;</TT><TT>550:     java.awt.TextField accountNumberTextField;</TT><TT>551:     java.awt.TextField accountTypeTextField;</TT><TT>552:     java.awt.TextField creationDateTextField;</TT><TT>553:     java.awt.TextField currentBalanceTextField;</TT><TT>554:     java.awt.Label accountInfoLabel;</TT><TT>555:     java.awt.Label issuingBankLabel;</TT><TT>556:     java.awt.Label accountNumberLabel;</TT><TT>557:     java.awt.Label accountTypeLabel;</TT><TT>558:     java.awt.Label creationDateLabel;</TT><TT>559:     java.awt.Label currentBalanceLabel;</TT><TT>560:     java.awt.Label dollarLabel1;</TT><TT>561:     java.awt.Panel transactionsPanel;</TT><TT>562:     java.awt.TextField transactionTextField;</TT><TT>563:     java.awt.Button depositButton;</TT><TT>564:     java.awt.Button withdrawButton;</TT><TT>565:     java.awt.Button updateAccountButton;</TT><TT>566:     java.awt.Label transactionsLabel;</TT><TT>567:     java.awt.Label dollarLabel2;</TT><TT>568:     java.awt.TextField statusTextField;</TT><TT>569:     //}}</TT><TT>570: </TT><TT>571:     /**</TT><TT>572:      * Set the status bar message to the given string. If the</TT><TT>573:      * string is null, the status message is reset to the default.</TT><TT>574:      */</TT><TT>575:     public void setStatus(String status) {</TT><TT>576: </TT><TT>577:         if (status != null) {</TT><TT>578:             statusTextField.setText(status);</TT><TT>579:         } else {</TT><TT>580:             statusTextField.setText(&quot;BankApplet ready.&quot;);</TT><TT>581:         }</TT><TT>582:     }</TT><TT>583: </TT><TT>584:     /**</TT><TT>585:      * Update the given Account with the new balance.</TT><TT>586:      */</TT><TT>587:     public void update(Account account, float balance) {</TT><TT>588: </TT><TT>589:         setStatus(&quot;Received AutoUpdate for Account \&quot;&quot; + ((Bank)</TT><TT>590:                 myAccountBankMap.get(mySelectedAccount)).name() +</TT><TT>591:                 &quot;:&quot; + account.accountNumber() + &quot;\&quot;&quot;);</TT><TT>592: </TT><TT>593:         // If the updated Account is currently selected, update the</TT><TT>594:         // display immediately.</TT><TT>595:         if (account._is_equivalent(mySelectedAccount)) {</TT><TT>596:             currentBalanceTextField.setText(String.</TT><TT>597:                     valueOf(balance));</TT><TT>598:         }</TT><TT>599:     }</TT><TT>600: </TT><TT>601:     /**</TT><TT>602:      * Add the given array of Banks to the Bank choice box and to</TT><TT>603:      * this BankApplet's internal data structures.</TT><TT>604:      */</TT><TT>605:     protected void addBanks(Bank[] banks) {</TT><TT>606: </TT><TT>607:         for (int i = 0; i &lt; banks.length; i++) {</TT><TT>608:             String name = banks[i].name();</TT><TT>609:             myBanks.put(name, banks[i]);</TT><TT>610:             bankChoice.add(name);</TT><TT>611:         }</TT><TT>612:         if (mySelectedBank == null &amp;&amp; banks.length &gt; 0) {</TT><TT>613:             mySelectedBank = banks[0];</TT><TT>614:         }</TT><TT>615:     }</TT><TT>616: </TT><TT>617:     /**</TT><TT>618:      * Add the given array of ATMs to the ATM choice box and to</TT><TT>619:      * this BankApplet's internal data structures.</TT><TT>620:      */</TT><TT>621:     protected void addATMs(ATM[] atms) {</TT><TT>622: </TT><TT>623:         for (int i = 0; i &lt; atms.length; i++) {</TT><TT>624:             String name = atms[i].name();</TT><TT>625:             myATMs.put(name, atms[i]);</TT><TT>626:             atmChoice.add(name);</TT><TT>627:         }</TT><TT>628:         if (mySelectedATM == null &amp;&amp; atms.length &gt; 0) {</TT><TT>629:             mySelectedATM = atms[0];</TT><TT>630:         }</TT><TT>631:     }</TT><TT>632: </TT><TT>633:     /**</TT><TT>634:      * Create a new Customer with the given name, Social Security</TT><TT>635:      * number, address, mother's maiden name, and PIN.</TT><TT>636:      */</TT><TT>637:     protected void createCustomer(String name, String</TT><TT>638:             socialSecurityNumber, String address, String</TT><TT>639:             mothersMaidenName) {</TT><TT>640: </TT><TT>641:         // Create a new Customer and register it with the BOA.</TT><TT>642:         setStatus(&quot;Creating new Customer...&quot;);</TT><TT>643:         CustomerImpl customer = new CustomerImpl(name,</TT><TT>644:                 socialSecurityNumber, address, mothersMaidenName,</TT><TT>645:                 this);</TT><TT>646:         myBOA.obj_is_ready(customer);</TT><TT>647:         myCustomers.put(name, customer);</TT><TT>648:         customerChoice.add(name);</TT><TT>649:         if (mySelectedCustomer == null) {</TT><TT>650:             mySelectedCustomer = customer;</TT><TT>651:         }</TT><TT>652: </TT><TT>653:         // Now that there is a Customer selected, the Account</TT><TT>654:         // operations can be enabled.</TT><TT>655:         accountChoice.setEnabled(true);</TT><TT>656:         newAccountButton.setEnabled(true);</TT><TT>657: </TT><TT>658:         setStatus(null);</TT><TT>659:     }</TT><TT>660: </TT><TT>661:     /**</TT><TT>662:      * Create a new Account with the given owner, Account type, and</TT><TT>663:      * initial balance.</TT><TT>664:      */</TT><TT>665:     protected void createAccount(Customer owner, String type, float</TT><TT>666:             initialBalance) {</TT><TT>667: </TT><TT>668:         setStatus(&quot;Creating new Account...&quot;);</TT><TT>669:         Account account = mySelectedBank.createAccount(owner, type,</TT><TT>670:                 initialBalance);</TT><TT>671:         Hashtable accounts = (Hashtable)myAccounts.</TT><TT>672:                 get(mySelectedCustomer);</TT><TT>673: </TT><TT>674:         // If there doesn't exist an index of Accounts for this</TT><TT>675:         // Customer already, create one.</TT><TT>676:         if (accounts == null) {</TT><TT>677:             accounts = new Hashtable();</TT><TT>678:             myAccounts.put(mySelectedCustomer, accounts);</TT><TT>679:         }</TT><TT>680:         String accountName = mySelectedBank.name() + &quot;:&quot; + account.</TT><TT>681:                 accountNumber();</TT><TT>682:         accounts.put(accountName, account);</TT><TT>683:         accountChoice.add(accountName);</TT><TT>684:         myAccountBankMap.put(account, mySelectedBank);</TT><TT>685: </TT><TT>686:         if (mySelectedAccount == null) {</TT><TT>687:             mySelectedAccount = account;</TT><TT>688:         }</TT><TT>689: </TT><TT>690:         // Now that there is an Account selected, the Account</TT><TT>691:         // features can be enabled. Also update the Account info</TT><TT>692:         // display.</TT><TT>693:         enableAccountFeatures(true);</TT><TT>694:         updateAccountInfo();</TT><TT>695: </TT><TT>696:         setStatus(null);</TT><TT>697:     }</TT><TT>698: </TT><TT>699:     /**</TT><TT>700:      * Enable/disable the Account-related features.</TT><TT>701:      */</TT><TT>702:     protected void enableAccountFeatures(boolean enable) {</TT><TT>703: </TT><TT>704:         autoUpdateButton.enable(enable);</TT><TT>705:         transactionTextField.enable(enable);</TT><TT>706:         depositButton.enable(enable);</TT><TT>707:         withdrawButton.enable(enable);</TT><TT>708:         updateAccountButton.enable(enable);</TT><TT>709:         if (!enable) {</TT><TT>710:             issuingBankTextField.setText(&quot;&quot;);</TT><TT>711:             accountNumberTextField.setText(&quot;&quot;);</TT><TT>712:             accountTypeTextField.setText(&quot;&quot;);</TT><TT>713:             creationDateTextField.setText(&quot;&quot;);</TT>

⌨️ 快捷键说明

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