home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-30 | 5.0 KB | 163 lines |
- package borland.samples.intl;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.control.*;
- import borland.samples.intl.gui.*;
- import borland.samples.intl.application.*;
-
- /**
- * Launches the International Sample Application. Constructed using
- * the Applet Wizard, IntlDemo.java works both as an applet and an
- * application. When run as an application without
- * command-line parameters, TextDataFiles are used as the data source.
- * If JDBC connection parameters are passed as command-line
- * parameters, the specified JDBC database will be used.
- * Running as an applet displays a button which when pushed
- * starts running the application.
- */
- public class IntlDemo extends Applet {
- XYLayout xYLayout1 = new XYLayout();
- static boolean isStandalone = false;
- ButtonControl buttonControl1 = new ButtonControl();
- private boolean framesInitialized = false;
-
- //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 IntlDemo() {
- }
-
- //Initialize the applet
- public void init() {
- try {
- jbInit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- // Component initialization
- public void jbInit() throws Exception{
- xYLayout1.setWidth(284);
- xYLayout1.setHeight(132);
- buttonControl1.setFont(new Font("Dialog", 2, 14));
- buttonControl1.setImageURL(IntlDemo.class.getResource("beans/resources/LocaleChooserIconColor32.gif"));
- buttonControl1.setLabel("Click here to begin...");
- buttonControl1.addActionListener(new IntlDemo_buttonControl1_actionAdapter(this));
- this.setLayout(xYLayout1);
- this.add(buttonControl1, new XYConstraints(17, 18, 251, 43));
- }
-
- //Start the applet
- public void start() {
- if (framesInitialized) {
- WelcomeFrame.getInstance().setBackgroundActivityEnabled(true);
- }
- }
-
- //Stop the applet
- public void stop() {
- if (framesInitialized) {
- WelcomeFrame.getInstance().setBackgroundActivityEnabled(false);
- }
- }
-
- //Destroy the applet and dispose of frames
- public void destroy() {
- if (framesInitialized) {
- WelcomeFrame.getInstance().dispose();
- ProductFrame.getInstance().dispose();
- OrderFrame.getInstance().dispose();
- }
- }
-
- //Get Applet information
- public String getAppletInfo() {
- return "IntlDemo Applet";
- }
-
- //Get parameter info
- public String[][] getParameterInfo() {
- return null;
- }
-
- //Main method
- static public void main(String[] argv) {
- isStandalone = true;
- try {
- if ((argv.length != 0) && (argv.length != 4)) {
- System.out.println("Usage: java IntlDemo");
- System.out.println(" runs demo using a TextDataFile data source");
- System.out.println("Usage: java IntlDemo [url user password driver]");
- System.out.println(" runs demo using the specified JDBC data source");
- System.exit(0);
- }
- if (argv.length == 4) {
- System.out.println("Using JDBC data source with the following parameters:");
- System.out.println("url: " + argv[0]);
- System.out.println("user: " + argv[1]);
- System.out.println("password: " + argv[2]);
- System.out.println("driver: " + argv[3]);
- // set JDBC data source
- AppDataModule.setJDBCDataSource(argv[0], argv[1], argv[2], argv[3]);
- } else {
- System.out.println("Using TextDataFile data source");
- }
-
- // load and display welcome frame
- System.out.print("Loading...");
- WelcomeFrame.getInstance().setVisible(true);
- System.out.println("...Done");
- // pre-load other frames used by the sample
- ProductFrame.getInstance();
- OrderFrame.getInstance();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- };
- }
-
- void buttonControl1_actionPerformed(ActionEvent e) {
- if (framesInitialized == false) {
- framesInitialized = true;
-
- // set JDBC data source
- AppDataModule.setJDBCDataSource(getParameter("url"),
- getParameter("user"),
- getParameter("password"),
- getParameter("driver"));
- WelcomeFrame.setRunningAsApplet(true);
-
- // tell WelcomeFrame to run in applet mode
- // load frames used by the sample
- WelcomeFrame.getInstance();
- ProductFrame.getInstance();
- OrderFrame.getInstance();
- WelcomeFrame.getInstance().setVisible(true);
- } else {
- WelcomeFrame.getInstance().setVisible(true);
- }
- }
- }
-
- class IntlDemo_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
- IntlDemo adaptee;
-
- IntlDemo_buttonControl1_actionAdapter(IntlDemo adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.buttonControl1_actionPerformed(e);
- }
- }
-
-
-