home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 6.7 KB | 214 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- //--------------------------------------------------------------------------------------------------
- // CORBA Reference Application
- // Copyright (c) 1997 by Borland International, All Rights Reserved
- //
- // Credit Approval Applet
- //--------------------------------------------------------------------------------------------------
-
- package borland.reference.creditapproval.client;
-
- import borland.jbcl.control.*;
- import borland.jbcl.layout.*;
- import java.applet.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import borland.reference.creditapproval.CORBAInterface.*;
- import borland.reference.creditapproval.client.Res;
-
- public class CreditApprovalApplet extends Applet {
- boolean isStandalone = false;
- CreditApprovalDispenser objectDispenser;
- CreditApproval creditApproval;
- CardLayout cardLayout1 = new CardLayout();
- CallbackThread callbackControlThread;
- private ApplicationFormPanel applicantPanel;
- private ApplicationApprovedPanel approvedPanel;
- private ApplicationDeniedPanel deniedPanel;
- private SystemErrorPanel errorPanel;
- Frame browserFrame;
- private final String imageFolder = "Images";
- ResourceBundle res = Res.getBundle("borland.reference.creditapproval.client.Res");
-
- //Get a parameter value
- public String getParameter(String key, String def) {
- return isStandalone ? System.getProperty(key, def) :
- (getParameter(key) != null ? getParameter(key) : def);
- }
-
- //Construct the applet
- public CreditApprovalApplet() {
- callbackControlThread = new CallbackThread();
- callbackControlThread.start();
- callbackControlThread.setPriority( Thread.NORM_PRIORITY + 1 );
- }
-
- public String getImageLocation() {
- return this.getCodeBase() + imageFolder + java.io.File.separator;
- }
- //Initialize the applet
- public void init() {
-
- // Get the frame
- Component comp = this;
- while (!(comp instanceof Frame) ) comp = comp.getParent();
- browserFrame = (Frame) comp;
-
- try {
- jbInit();
- } catch (Exception e) {
- e.printStackTrace(); }
- }
-
- /**
- * Initialize Components
- */
- private void jbInit() throws Exception{
- this.setLayout(cardLayout1);
- this.setSize(new Dimension(722, 403));
- applicantPanel = new ApplicationFormPanel(this);
- approvedPanel = new ApplicationApprovedPanel(this);
- deniedPanel = new ApplicationDeniedPanel(this);
- errorPanel = new SystemErrorPanel(this);
- add(applicantPanel, "Applicant Form" );
- add(approvedPanel, "Approved" );
- add(deniedPanel, "Denied" );
- add(errorPanel, "Error");
- browserFrame.pack();
- }
-
- /**
- * Start the applet
- */
- public void start() {
- }
-
- /**
- * Apply for a credit card using the specified Application Information
- * This method submits the applicant information to the CORBA Server
- * object.
- */
- public void applyForCard(applicantInfoStruct appInfo) {
-
- callbackControlThread.getCallback().updateStatusText(res.getString("Connecting_to_Server") + "...");
- try {
- // Initialize the ORB
- org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
-
- // Bind to the dispenser object!
- objectDispenser =
- CreditApprovalDispenserHelper.bind(orb, "Main Dispenser");
-
- // Reserve a credit approval object
- creditApproval = objectDispenser.reserveCreditApprovalObject();
-
- creditApprovalStruct creditCardInfo;
- try {
- creditCardInfo = creditApproval.getCreditApproval( appInfo, callbackControlThread.getCallback() );
-
- // Display the Credit Card Information to the user using the Approved Panel
- approvedPanel.setCreditCardInformation( creditCardInfo );
- ((CardLayout) this.getLayout()).show( this, "Approved" );
-
- } catch (CreditApprovalException e ) {
-
- // Display the error to the user using the Error Panel
- errorPanel.setError( e.reason );
- ((CardLayout) this.getLayout()).show( this, "Error" );
- } catch (CreditDeniedException e ) {
-
- // Use the Denied Panel to explain why the application was not approved
- deniedPanel.setReason( e.reason );
- ((CardLayout) this.getLayout()).show( this, "Denied" );
- System.out.println( e.reason );
- } catch( Exception e) {
-
- // Display the error to the user using the Error Panel
- errorPanel.setError( e.getMessage() );
- ((CardLayout) this.getLayout()).show( this, "Error" );
- }
-
- try{
-
- // Release the reserved approval object
- objectDispenser.releaseCreditApprovalObject(creditApproval);
- } catch (Exception e)
- {
- System.err.println(e);
- }
- } catch (org.omg.CORBA.NO_IMPLEMENT e) {
- // Display the error to the user using the Error Panel
- errorPanel.setError( res.getString("Server_Down") );
- ((CardLayout) this.getLayout()).show( this, "Error" );
-
- } catch (Exception e) {
-
- // Display the error to the user using the Error Panel
- errorPanel.setError( e.getMessage() );
- ((CardLayout) this.getLayout()).show( this, "Error" );
- }
-
- // Reset the status text
- callbackControlThread.getCallback().updateStatusText("");
- }
-
- /**
- * Stop the applet
- */
- public void stop() {
- }
-
- /**
- * Get Applet information
- */
- public String getAppletInfo() {
- return "Cliffhanger Credit Card Application Applet";
- }
-
- /**
- * Get parameter info
- */
- public String[][] getParameterInfo() {
- return null;
- }
-
- /**
- * Stops the execution of the App/Applet
- */
- public void destroyApplet() {
- if (!isStandalone) {
- stop();
- destroy();
- }
- System.exit(0);
- }
-
- /**
- * Displays the Application Form Pane
- */
- public void displayApplication() {
- ((CardLayout) this.getLayout()).show( this, "Applicant Form" );
- }
-
- }
-
-