home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / IntlDemo.java < prev    next >
Text File  |  1998-05-08  |  7KB  |  193 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. package borland.samples.intl;
  21.  
  22. import java.awt.*;
  23. import java.awt.event.*;
  24. import java.applet.*;
  25. import borland.jbcl.layout.*;
  26. import borland.jbcl.control.*;
  27. import borland.samples.intl.application.*;
  28. import borland.samples.intl.beans.*;
  29. import borland.samples.intl.gui.*;
  30. import com.sun.java.swing.UIManager;
  31.  
  32. /**
  33.  * Launches the International Sample Application.  Constructed using
  34.  * the Applet Wizard, IntlDemo.java works both as an applet and an
  35.  * application.  When run as an application without
  36.  * command-line parameters, TextDataFiles are used as the data source.
  37.  * If JDBC connection parameters are passed as command-line
  38.  * parameters, the specified JDBC database will be used.
  39.  * Running as an applet displays a button which when pushed
  40.  * starts running the application.
  41.  */
  42. public class IntlDemo extends Applet {
  43.   XYLayout xYLayout1 = new XYLayout();
  44.   static boolean isStandalone = false;
  45.   ButtonControl buttonControl1 = new ButtonControl();
  46.   private boolean framesInitialized = false;
  47.   Panel panel1 = new Panel();
  48.   BorderLayout borderLayout1 = new BorderLayout();
  49.   Frame frame = null;
  50.  
  51.   //Get a parameter value
  52.   public String getParameter(String key, String def) {
  53.     return isStandalone ? System.getProperty(key, def) :
  54.       (getParameter(key) != null ? getParameter(key) : def);
  55.   }
  56.  
  57.   //Construct the applet
  58.   public IntlDemo() {
  59.   }
  60.  
  61.   //Initialize the applet
  62.   public void init() {
  63.     try {
  64.       jbInit();
  65.     } catch (Exception e) {
  66.       e.printStackTrace();
  67.     }
  68.   }
  69.  
  70.   // Component initialization
  71.   public void jbInit() throws Exception{
  72.     buttonControl1.setFont(new Font("Dialog", 2, 14));
  73.     buttonControl1.setImage(createImage((java.awt.image.ImageProducer) this.getClass().getResource("beans/resources/LocaleChooserIconColor32.gif").getContent()));
  74.     buttonControl1.setLabel(getParameter("appletButtonStart"));
  75.     buttonControl1.addActionListener(new IntlDemo_buttonControl1_actionAdapter(this));
  76.     this.setLayout(borderLayout1);
  77.     this.add(panel1, BorderLayout.CENTER);
  78.     panel1.add(buttonControl1, null);
  79.   }
  80.  
  81.   //Start the applet
  82.   public void start() {
  83.     if (framesInitialized) {
  84.       WelcomeFrame.getInstance().setBackgroundActivityEnabled(true);
  85.     }
  86.   }
  87.  
  88.   //Stop the applet
  89.   public void stop() {
  90.     if (framesInitialized) {
  91.       WelcomeFrame.getInstance().setBackgroundActivityEnabled(false);
  92.     }
  93.   }
  94.  
  95.   //Destroy the applet and dispose of frames
  96.   public void destroy() {
  97.     if (framesInitialized) {
  98.       WelcomeFrame.getInstance().dispose();
  99.       ProductFrame.getInstance().dispose();
  100.       OrderFrame.getInstance().dispose();
  101.     }
  102.   }
  103.  
  104.   //Get Applet information
  105.   public String getAppletInfo() {
  106.     return "IntlDemo Applet";
  107.   }
  108.  
  109.   //Get parameter info
  110.   public String[][] getParameterInfo() {
  111.     return null;
  112.   }
  113.  
  114.   //Main method
  115.   static public void main(String[] argv) {
  116.     isStandalone = true;
  117.     try {
  118.       if ((argv.length != 0) && (argv.length != 4)) {
  119.         System.out.println("Usage: java IntlDemo");
  120.         System.out.println("       runs demo using a TextDataFile data source");
  121.         System.out.println("Usage: java IntlDemo [url user password driver]");
  122.         System.out.println("       runs demo using the specified JDBC data source");
  123.         System.exit(0);
  124.       }
  125.       if (argv.length == 4) {
  126.         System.out.println("Using JDBC data source with the following parameters:");
  127.         System.out.println("url: " + argv[0]);
  128.         System.out.println("user: " + argv[1]);
  129.         System.out.println("password: " + argv[2]);
  130.         System.out.println("driver: " + argv[3]);
  131.         // set JDBC data source
  132.         AppDataModule.setJDBCDataSource(argv[0], argv[1], argv[2], argv[3]);
  133.       } else {
  134.         System.out.println("Using TextDataFile data source");
  135.       }
  136.  
  137.       UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
  138.       // show loading screen
  139.       LoadingFrame loadingFrame = new LoadingFrame();
  140.       loadingFrame.setImageName("Loading.gif");
  141.       loadingFrame.setTitle("IntlDemo");
  142.       loadingFrame.setVisible(true);
  143.  
  144.       // pre-load frames used by the sample
  145.       WelcomeFrame.getInstance();
  146.       ProductFrame.getInstance();
  147.       OrderFrame.getInstance();
  148.       loadingFrame.dispose();
  149.       // display welcome frame
  150.       WelcomeFrame.getInstance().setVisible(true);
  151.     } catch (Exception e) {
  152.       e.printStackTrace();
  153.       System.exit(1);
  154.     };
  155.   }
  156.  
  157.   void buttonControl1_actionPerformed(ActionEvent e) {
  158.     if (framesInitialized == false) {
  159.       framesInitialized = true;
  160.  
  161.       setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  162.       // set JDBC data source
  163.       AppDataModule.setJDBCDataSource(getParameter("url"),
  164.                                       getParameter("user"),
  165.                                       getParameter("password"),
  166.                                       getParameter("driver"));
  167.       WelcomeFrame.setRunningAsApplet(true);
  168.  
  169.       // tell WelcomeFrame to run in applet mode
  170.       // load frames used by the sample
  171.       WelcomeFrame.getInstance();
  172.       ProductFrame.getInstance();
  173.       OrderFrame.getInstance();
  174.       setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  175.     }
  176.     WelcomeFrame.getInstance().setVisible(true);
  177.   }
  178. }
  179.  
  180. class IntlDemo_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
  181.   IntlDemo adaptee;
  182.  
  183.   IntlDemo_buttonControl1_actionAdapter(IntlDemo adaptee) {
  184.     this.adaptee = adaptee;
  185.   }
  186.  
  187.   public void actionPerformed(ActionEvent e) {
  188.     adaptee.buttonControl1_actionPerformed(e);
  189.   }
  190. }
  191.  
  192.  
  193.