home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JVISBRKR.Z / CreditApprovalApplet.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  6.7 KB  |  214 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. //--------------------------------------------------------------------------------------------------
  21. // CORBA Reference Application
  22. // Copyright (c) 1997 by Borland International, All Rights Reserved
  23. //
  24. // Credit Approval Applet
  25. //--------------------------------------------------------------------------------------------------
  26.  
  27. package borland.reference.creditapproval.client;
  28.  
  29. import borland.jbcl.control.*;
  30. import borland.jbcl.layout.*;
  31. import java.applet.*;
  32. import java.awt.*;
  33. import java.awt.event.*;
  34. import java.util.*;
  35. import borland.reference.creditapproval.CORBAInterface.*;
  36. import borland.reference.creditapproval.client.Res;
  37.  
  38. public class CreditApprovalApplet extends Applet {
  39.   boolean isStandalone = false;
  40.   CreditApprovalDispenser objectDispenser;
  41.   CreditApproval creditApproval;
  42.   CardLayout cardLayout1 = new CardLayout();
  43.   CallbackThread callbackControlThread;
  44.   private ApplicationFormPanel applicantPanel;
  45.   private ApplicationApprovedPanel approvedPanel;
  46.   private ApplicationDeniedPanel deniedPanel;
  47.   private SystemErrorPanel errorPanel;
  48.   Frame browserFrame;
  49.   private final String imageFolder = "Images";
  50.   ResourceBundle res = Res.getBundle("borland.reference.creditapproval.client.Res"); 
  51.  
  52.   //Get a parameter value
  53.   public String getParameter(String key, String def) {
  54.     return isStandalone ? System.getProperty(key, def) :
  55.       (getParameter(key) != null ? getParameter(key) : def);
  56.   }
  57.  
  58.   //Construct the applet
  59.   public CreditApprovalApplet() {
  60.     callbackControlThread = new CallbackThread();
  61.     callbackControlThread.start();
  62.     callbackControlThread.setPriority( Thread.NORM_PRIORITY + 1 );
  63.   }
  64.  
  65.   public String getImageLocation() {
  66.     return this.getCodeBase() + imageFolder + java.io.File.separator;
  67.   }
  68.   //Initialize the applet
  69.   public void init() {
  70.  
  71.     // Get the frame
  72.     Component comp = this;
  73.     while (!(comp instanceof Frame) ) comp = comp.getParent();
  74.     browserFrame = (Frame) comp;
  75.  
  76.     try {
  77.       jbInit();
  78.     } catch (Exception e) {
  79.     e.printStackTrace(); }
  80.   }
  81.   
  82.   /**
  83.   * Initialize Components
  84.   */
  85.   private void jbInit() throws Exception{
  86.     this.setLayout(cardLayout1);
  87.     this.setSize(new Dimension(722, 403));
  88.     applicantPanel = new ApplicationFormPanel(this);
  89.     approvedPanel = new ApplicationApprovedPanel(this);
  90.     deniedPanel = new ApplicationDeniedPanel(this);
  91.     errorPanel = new SystemErrorPanel(this);
  92.     add(applicantPanel, "Applicant Form" );
  93.     add(approvedPanel,  "Approved" );
  94.     add(deniedPanel,    "Denied" );
  95.     add(errorPanel,     "Error");
  96.     browserFrame.pack();
  97.   }
  98.  
  99.   /**
  100.   * Start the applet
  101.   */
  102.   public void start() {
  103.   }
  104.  
  105.   /**
  106.   * Apply for a credit card using the specified Application Information
  107.   * This method submits the applicant information to the CORBA Server
  108.   * object.
  109.   */
  110.   public void applyForCard(applicantInfoStruct appInfo) {
  111.  
  112.     callbackControlThread.getCallback().updateStatusText(res.getString("Connecting_to_Server") + "...");
  113.     try {
  114.       // Initialize the ORB
  115.       org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
  116.  
  117.       // Bind to the dispenser object!
  118.       objectDispenser =
  119.          CreditApprovalDispenserHelper.bind(orb, "Main Dispenser");
  120.  
  121.       // Reserve a credit approval object
  122.       creditApproval = objectDispenser.reserveCreditApprovalObject();
  123.  
  124.       creditApprovalStruct creditCardInfo;
  125.       try {
  126.         creditCardInfo = creditApproval.getCreditApproval( appInfo, callbackControlThread.getCallback() );
  127.  
  128.         // Display the Credit Card Information to the user using the Approved Panel
  129.         approvedPanel.setCreditCardInformation( creditCardInfo );
  130.         ((CardLayout) this.getLayout()).show( this, "Approved" );
  131.  
  132.       } catch (CreditApprovalException e ) {
  133.  
  134.         // Display the error to the user using the Error Panel
  135.         errorPanel.setError( e.reason );
  136.         ((CardLayout) this.getLayout()).show( this, "Error" );
  137.       } catch (CreditDeniedException e ) {
  138.  
  139.         // Use the Denied Panel to explain why the application was not approved
  140.         deniedPanel.setReason( e.reason );
  141.         ((CardLayout) this.getLayout()).show( this, "Denied" );
  142.         System.out.println( e.reason );
  143.       } catch( Exception e) {
  144.  
  145.         // Display the error to the user using the Error Panel
  146.         errorPanel.setError( e.getMessage() );
  147.         ((CardLayout) this.getLayout()).show( this, "Error" );
  148.       }
  149.  
  150.       try{
  151.  
  152.         // Release the reserved approval object
  153.         objectDispenser.releaseCreditApprovalObject(creditApproval);
  154.       } catch (Exception e)
  155.       {
  156.         System.err.println(e);
  157.       }
  158.     } catch (org.omg.CORBA.NO_IMPLEMENT e) {
  159.       // Display the error to the user using the Error Panel
  160.       errorPanel.setError( res.getString("Server_Down") );
  161.       ((CardLayout) this.getLayout()).show( this, "Error" );
  162.  
  163.     } catch (Exception e) {
  164.  
  165.       // Display the error to the user using the Error Panel
  166.       errorPanel.setError( e.getMessage() );
  167.       ((CardLayout) this.getLayout()).show( this, "Error" );
  168.     }
  169.  
  170.     // Reset the status text
  171.     callbackControlThread.getCallback().updateStatusText("");
  172.   }
  173.  
  174.   /**
  175.   * Stop the applet
  176.   */
  177.   public void stop() {
  178.   }
  179.  
  180.   /**
  181.   * Get Applet information
  182.   */
  183.   public String getAppletInfo() {
  184.     return "Cliffhanger Credit Card Application Applet";
  185.   }
  186.  
  187.   /**
  188.   * Get parameter info
  189.   */
  190.   public String[][] getParameterInfo() {
  191.     return null;
  192.   }
  193.  
  194.   /**
  195.   * Stops the execution of the App/Applet
  196.   */
  197.   public void destroyApplet() {
  198.     if (!isStandalone) {
  199.       stop();
  200.       destroy();
  201.     }
  202.     System.exit(0);
  203.   }
  204.  
  205.   /**
  206.   * Displays the Application Form Pane
  207.   */
  208.   public void displayApplication() {
  209.     ((CardLayout) this.getLayout()).show( this, "Applicant Form" );
  210.   }
  211.  
  212. }
  213.  
  214.