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

📄 creditapprovalapplet.java

📁 java在线商店的源代码。编写十分规范的哦
💻 JAVA
字号:
/**
 * Copyright (c) 1996-2004 Borland Software Corporation.  All Rights Reserved.
 * 
 * This SOURCE CODE FILE, which has been provided by Borland Software as part
 * of a Borland Software product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of Borland Software.  
 *
 * 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 SOFTWARE, 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.
 */
//------------------------------------------------------------------------------
// Copyright (c) 1996-2004 Borland Software Corporation.  All Rights Reserved.
//------------------------------------------------------------------------------

package com.borland.samples.creditapproval.client;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;

import com.borland.samples.creditapproval.CORBAInterface.*;
import com.borland.samples.creditapproval.client.Res;

/**
 * The main CreditApproval applet.
 *<P>
 * Main features illustrated in this class are:
 *<UL>
 *<LI>An applet which can also run as a standalone application.
 *<LI>Binding to a CORBA servant via a portable object adapter.
 *<LI>CORBA exception handling.
 *<LI>Use of CardLayout to display a multi-page form.
 *</UL>
 */
public class CreditApprovalApplet extends JApplet {
  boolean isStandalone = false;
  CreditApprovalDispenser objectDispenser;
  CreditApproval creditApproval;
  JPanel contentPane;
  CardLayout cardLayout1 = new CardLayout();
  ApplicationFormPanel applicantPanel1 = new ApplicationFormPanel();
  ApplicationApprovedPanel approvedPanel1 = new ApplicationApprovedPanel();
  ApplicationDeniedPanel deniedPanel1 = new ApplicationDeniedPanel();
  SystemErrorPanel errorPanel1 = new SystemErrorPanel();
  ResourceBundle res = Res.getBundle("com.borland.samples.creditapproval.client.Res");

  CallbackThread callbackControlThread;
  private static boolean clientValidationEnabled = true;


  /**
   * main method to enable running this class as an application
   * @param args String[]
   */
  public static void main(String[] args) {
    CreditApprovalApplet applet = new CreditApprovalApplet();

    if (args.length > 0 && args[0].equals("disable")) {
      clientValidationEnabled = false;
    }

    // Running as an application
    applet.isStandalone = true;

    // Setup the container frame
    JFrame frame = new JFrame();
    frame.setTitle("");
    frame.getContentPane().add(applet, BorderLayout.CENTER);

    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
        System.exit(0);
      };
    });

    // Setup the applet
    applet.init();
    applet.start();

    // Pack the frame
    frame.pack();

    //Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height)
      frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
      frameSize.width = screenSize.width;
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

    // Show the frame containing the applet.
    frame.setVisible(true);
  }


  /**
   * Get a parameter value
   *
   * @param key String
   * @param def String
   * @return String
   */

     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);
  }

  /**
   * Initialize the applet
   */
  public void init() {
    try {
      jbInit();
      applicantPanel1.setCreditApprovalApplet(this);
      approvedPanel1.setCreditApprovalApplet(this);
      deniedPanel1.setCreditApprovalApplet(this);
      errorPanel1.setCreditApprovalApplet(this);
      cardLayout1.layoutContainer(contentPane);

      if (!isStandalone) {
        if (getParameter("clientValidationEnabled", "true").equals("false")) {
           clientValidationEnabled = false;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Initialize Components
   * @throws Exception exception
   */
  private void jbInit() throws Exception{
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(cardLayout1);
    this.setSize(new Dimension(722, 403));
    contentPane.add(applicantPanel1, "Applicant Form");
    contentPane.add(approvedPanel1, "Approved");
    contentPane.add(deniedPanel1, "Denied");
    contentPane.add(errorPanel1, "Error");
  }

  /**
   * 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.
   *
   * @param appInfo applicantInfoStruct
   *
   */
  public void applyForCard(applicantInfoStruct appInfo) {

    // This is invoked from the ApplicationFormPanel.
    // Display the WAIT_CURSOR since this operation could take a while
    applicantPanel1.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    callbackControlThread.getCallback().updateStatusText(res.getString("Connecting_to_Server"));
    try {
      // Initialize the ORB
      org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init((String[]) null, null);

      // Bind to the dispenser object!
      System.out.println("CreditApprovalPanel.applyForCard(): binding dispenser");
      objectDispenser =
         CreditApprovalDispenserHelper.bind(orb, "CreditApprovalDispenser");
      System.out.println("CreditApprovalPanel.applyForCard(): got dispenser");

      // Reserve a credit approval object
      System.out.println("CreditApprovalPanel.applyForCard(): reserving credit approval object");
      creditApproval = objectDispenser.reserveCreditApprovalObject();
      System.out.println("CreditApprovalPanel.applyForCard(): reserved credit approval object");

      creditApprovalStruct creditCardInfo;
      try {
        System.out.println("CreditApprovalPanel.applyForCard(): getting credit approval");
        creditCardInfo = creditApproval.getCreditApproval(appInfo, callbackControlThread.getCallback());
        System.out.println("CreditApprovalPanel.applyForCard(): got credit approval");

        // Display the Credit Card Information to the user using the Approved Panel
        approvedPanel1.setCreditCardInformation(creditCardInfo);
        System.out.println("CreditApprovalPanel.applyForCard(): showing Approved card layout");
        cardLayout1.show(contentPane, "Approved");
        System.out.println("CreditApprovalPanel.applyForCard(): showed Approved card layout");

      } catch (CreditApprovalException e) {

        // Display the error to the user using the Error Panel
        errorPanel1.setError(e.reason);
        System.out.println("CreditApprovalPanel.applyForCard(): showing error card layout");
        cardLayout1.show(contentPane, "Error");
        System.out.println("CreditApprovalPanel.applyForCard(): showed error card layout");
      } catch (CreditDeniedException e) {

        // Use the Denied Panel to explain why the application was not approved
        deniedPanel1.setReason(e.reason);
        System.out.println("CreditApprovalPanel.applyForCard(): showing denied card layout");
        cardLayout1.show(contentPane, "Denied");
        System.out.println("CreditApprovalPanel.applyForCard(): showed denied card layout");
        System.out.println(e.reason);
      } catch (Exception e) {

        // Display the error to the user using the Error Panel
        System.out.println("CreditApprovalPanel.applyForCard(): showing error panel card layout");
        errorPanel1.setError(e.getMessage());
        cardLayout1.show(contentPane, "Error");
        System.out.println("CreditApprovalPanel.applyForCard(): showed error panel card layout");
      }

      try {
        // Release the reserved approval object
        System.out.println("CreditApprovalApplet.applyForCard(): releasing credit approval object");
        objectDispenser.releaseCreditApprovalObject(creditApproval);
        System.out.println("CreditApprovalApplet.applyForCard(): released credit approval object");
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    } catch (org.omg.CORBA.NO_IMPLEMENT e) {
      // Display the error to the user using the Error Panel
      errorPanel1.setError(res.getString("Server_Down"));
      System.out.println("CreditApprovalApplet.applyForCard(): showing Server_Down error");
      cardLayout1.show(contentPane, "Error");
      System.out.println("CreditApprovalApplet.applyForCard(): showed Server_Down error");

    } catch (Exception e) {

      // Display the error to the user using the Error Panel
      errorPanel1.setError(e.getMessage());
      System.out.println("CreditApprovalApplet.applyForCard(): showing generic error");
      cardLayout1.show(contentPane, "Error");
      System.out.println("CreditApprovalApplet.applyForCard(): showed generic error");
    }

    // Reset the status text
    callbackControlThread.getCallback().updateStatusText(" ");

    // reset the cursor to the default cursor
    applicantPanel1.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }

  /**
   * Stop the applet
   */
  public void stop() {
  }

  /**
   * Get Applet information
   * @return String
   */
  public String getAppletInfo() {
    return "Cliffhanger Credit Card Application Applet";
  }

  /**
   * Get parameter info
   * @return String[][]
   */
  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() {
    cardLayout1.show(contentPane, "Applicant Form");
  }

  public boolean isClientValidationEnabled() {
    return clientValidationEnabled;
  }

}

⌨️ 快捷键说明

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