home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / IntlDemo.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  5.0 KB  |  163 lines

  1. package borland.samples.intl;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.applet.*;
  6. import borland.jbcl.layout.*;
  7. import borland.jbcl.control.*;
  8. import borland.samples.intl.gui.*;
  9. import borland.samples.intl.application.*;
  10.  
  11. /**
  12.  * Launches the International Sample Application.  Constructed using
  13.  * the Applet Wizard, IntlDemo.java works both as an applet and an
  14.  * application.  When run as an application without
  15.  * command-line parameters, TextDataFiles are used as the data source.
  16.  * If JDBC connection parameters are passed as command-line
  17.  * parameters, the specified JDBC database will be used.
  18.  * Running as an applet displays a button which when pushed
  19.  * starts running the application.
  20.  */
  21. public class IntlDemo extends Applet {
  22.   XYLayout xYLayout1 = new XYLayout();
  23.   static boolean isStandalone = false;
  24.   ButtonControl buttonControl1 = new ButtonControl();
  25.   private boolean framesInitialized = false;
  26.  
  27.   //Get a parameter value
  28.   public String getParameter(String key, String def) {
  29.     return isStandalone ? System.getProperty(key, def) :
  30.       (getParameter(key) != null ? getParameter(key) : def);
  31.   }
  32.  
  33.   //Construct the applet
  34.   public IntlDemo() {
  35.   }
  36.  
  37.   //Initialize the applet
  38.   public void init() {
  39.     try {
  40.       jbInit();
  41.     } catch (Exception e) {
  42.       e.printStackTrace();
  43.     }
  44.   }
  45.  
  46.   // Component initialization
  47.   public void jbInit() throws Exception{
  48.     xYLayout1.setWidth(284);
  49.     xYLayout1.setHeight(132);
  50.     buttonControl1.setFont(new Font("Dialog", 2, 14));
  51.     buttonControl1.setImageURL(IntlDemo.class.getResource("beans/resources/LocaleChooserIconColor32.gif"));
  52.     buttonControl1.setLabel("Click here to begin...");
  53.     buttonControl1.addActionListener(new IntlDemo_buttonControl1_actionAdapter(this));
  54.     this.setLayout(xYLayout1);
  55.     this.add(buttonControl1, new XYConstraints(17, 18, 251, 43));
  56.   }
  57.  
  58.   //Start the applet
  59.   public void start() {
  60.     if (framesInitialized) {
  61.       WelcomeFrame.getInstance().setBackgroundActivityEnabled(true);
  62.     }
  63.   }
  64.  
  65.   //Stop the applet
  66.   public void stop() {
  67.     if (framesInitialized) {
  68.       WelcomeFrame.getInstance().setBackgroundActivityEnabled(false);
  69.     }
  70.   }
  71.  
  72.   //Destroy the applet and dispose of frames
  73.   public void destroy() {
  74.     if (framesInitialized) {
  75.       WelcomeFrame.getInstance().dispose();
  76.       ProductFrame.getInstance().dispose();
  77.       OrderFrame.getInstance().dispose();
  78.     }
  79.   }
  80.  
  81.   //Get Applet information
  82.   public String getAppletInfo() {
  83.     return "IntlDemo Applet";
  84.   }
  85.  
  86.   //Get parameter info
  87.   public String[][] getParameterInfo() {
  88.     return null;
  89.   }
  90.  
  91.   //Main method
  92.   static public void main(String[] argv) {
  93.     isStandalone = true;
  94.     try {
  95.       if ((argv.length != 0) && (argv.length != 4)) {
  96.         System.out.println("Usage: java IntlDemo");
  97.         System.out.println("       runs demo using a TextDataFile data source");
  98.         System.out.println("Usage: java IntlDemo [url user password driver]");
  99.         System.out.println("       runs demo using the specified JDBC data source");
  100.         System.exit(0);
  101.       }
  102.       if (argv.length == 4) {
  103.         System.out.println("Using JDBC data source with the following parameters:");
  104.         System.out.println("url: " + argv[0]);
  105.         System.out.println("user: " + argv[1]);
  106.         System.out.println("password: " + argv[2]);
  107.         System.out.println("driver: " + argv[3]);
  108.         // set JDBC data source
  109.         AppDataModule.setJDBCDataSource(argv[0], argv[1], argv[2], argv[3]);
  110.       } else {
  111.         System.out.println("Using TextDataFile data source");
  112.       }
  113.  
  114.       // load and display welcome frame
  115.       System.out.print("Loading...");
  116.       WelcomeFrame.getInstance().setVisible(true);
  117.       System.out.println("...Done");
  118.       // pre-load other frames used by the sample
  119.       ProductFrame.getInstance();
  120.       OrderFrame.getInstance();
  121.     } catch (Exception e) {
  122.       e.printStackTrace();
  123.       System.exit(1);
  124.     };
  125.   }
  126.  
  127.   void buttonControl1_actionPerformed(ActionEvent e) {
  128.     if (framesInitialized == false) {
  129.       framesInitialized = true;
  130.  
  131.       // set JDBC data source
  132.       AppDataModule.setJDBCDataSource(getParameter("url"),
  133.                       getParameter("user"),
  134.                       getParameter("password"),
  135.                       getParameter("driver"));
  136.       WelcomeFrame.setRunningAsApplet(true);
  137.  
  138.       // tell WelcomeFrame to run in applet mode
  139.       // load frames used by the sample
  140.       WelcomeFrame.getInstance();
  141.       ProductFrame.getInstance();
  142.       OrderFrame.getInstance();
  143.       WelcomeFrame.getInstance().setVisible(true);
  144.     } else {
  145.       WelcomeFrame.getInstance().setVisible(true);
  146.     }
  147.   }
  148. }
  149.  
  150. class IntlDemo_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
  151.   IntlDemo adaptee;
  152.  
  153.   IntlDemo_buttonControl1_actionAdapter(IntlDemo adaptee) {
  154.     this.adaptee = adaptee;
  155.   }
  156.  
  157.   public void actionPerformed(ActionEvent e) {
  158.     adaptee.buttonControl1_actionPerformed(e);
  159.   }
  160. }
  161.  
  162.  
  163.