home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / OrderTrackApplet.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  11.5 KB  |  289 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.  
  21. //Title:        Cliffhanger Order Status Tracker
  22. //Version:
  23. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  24. //Author:       Application Methods, Inc.
  25. //Description:  Cliffhanger Adventure Gear Order Status Tracking Applet
  26.  
  27. package borland.reference.tracker;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.applet.*;
  32. import borland.jbcl.layout.*;
  33. import borland.jbcl.control.*;
  34. import borland.sql.dataset.*;
  35. import borland.jbcl.dataset.*;
  36. import borland.jbcl.util.Variant;
  37. import java.util.*;
  38.  
  39. /**
  40.  * OrderTrackApplet defines the Applet subclass and user interface.  Customers
  41.  * would use this applet in a web-browser to find information about a recent
  42.  * order they had placed.  Given an order tracking number, they can find out
  43.  * status information, order and shipping dates, and the amount paid on the
  44.  * order.
  45.  * Note that this file also contains a frame wrapper that allows this Applet
  46.  * to be run as a standalone application.  Because an Applet is a subclass of
  47.  * panel, it can simply be wrapped in a frame as shown below so that it can
  48.  * be run as either Applet in a browser or standalone application.
  49.  */
  50. public class OrderTrackApplet extends Applet {
  51.   boolean isStandalone = false;
  52.   private QueryDataSet qdsPOrders;
  53.   private ParameterRow pRow;
  54.  
  55.   // Instantiate panels
  56.   BevelPanel getStatusPanel = new BevelPanel();
  57.   BevelPanel orderItemsPanel = new BevelPanel();
  58.  
  59.   // Instantiate layout managers for the panels
  60.   GridBagLayout gridBagLayoutApplet = new GridBagLayout();
  61.   GridBagLayout gridBagLayoutGSPanel = new GridBagLayout();
  62.   GridBagLayout gridBagLayoutOIPanel = new GridBagLayout();
  63.  
  64.   ImageControl titleGraphic = new ImageControl();
  65.  
  66.   // Instantiate field controls components
  67.   FieldControl orderNumberField = new FieldControl();
  68.   LabelControl orderNumberLabel = new LabelControl();
  69.   ButtonControl statusButton = new ButtonControl();
  70.   FieldControl orderStatusField = new FieldControl();
  71.   LabelControl orderStatusLabel = new LabelControl();
  72.   FieldControl orderDateField = new FieldControl();
  73.   LabelControl orderDateLabel = new LabelControl();
  74.   LabelControl shipDateLabel = new LabelControl();
  75.   FieldControl shipDateField = new FieldControl();
  76.   FieldControl amountField = new FieldControl();
  77.   LabelControl amountLabel = new LabelControl();
  78.   ResourceBundle res = Res.getBundle("borland.reference.tracker.Res");
  79.  
  80.   //Get a parameter value
  81.   public String getParameter(String key, String def) {
  82.     return isStandalone ? System.getProperty(key, def) :
  83.       (getParameter(key) != null ? getParameter(key) : def);
  84.   }
  85.  
  86.   //Construct the applet
  87.   public OrderTrackApplet() {
  88.   }
  89.  
  90.   //Initialize the applet
  91.   public void init() {
  92.     try {
  93.         // Initialize form objects
  94.         jbInit();
  95.         // Initialize data objects
  96.         initData();
  97.  
  98.     } catch (Exception e) {
  99.       e.printStackTrace();
  100.     }
  101.   }
  102.  
  103.   //Component initialization
  104.   private void jbInit() throws Exception{
  105.     this.setBackground(new Color(0, 0, 74));
  106.     this.setSize(new Dimension(414, 176));
  107.  
  108.     titleGraphic.setBackground(new Color(0, 0, 74));
  109.     titleGraphic.setImageName(".\\graphics\\StatusT.gif");
  110.  
  111.     getStatusPanel.setBackground(new Color(0, 0, 74));
  112.     getStatusPanel.setBevelInner(BevelPanel.FLAT);
  113.     getStatusPanel.setMargins(new Insets(2, 2, 2, 2));
  114.     getStatusPanel.setLayout(gridBagLayoutGSPanel);
  115.  
  116.     orderStatusField.setBackground(new Color(231, 231, 232));
  117.     orderStatusField.setColumnName("Status");
  118.     orderStatusField.setFont(new Font("Dialog", 1, 12));
  119.     orderStatusField.setForeground(new Color(50, 45, 215));
  120.     orderStatusField.setReadOnly(true);
  121.     orderStatusLabel.setAlignment(Label.RIGHT);
  122.     orderStatusLabel.setFont(new Font("Serif", 1, 12));
  123.     orderStatusLabel.setForeground(Color.yellow);
  124.     orderStatusLabel.setText(res.getString("Order_Status"));
  125.  
  126.  
  127.     orderDateField.setColumnName("orderDate");
  128.     orderDateField.setFont(new Font("Dialog", 1, 12));
  129.     orderDateField.setBackground(new Color(231, 231, 232));
  130.     orderDateField.setEnabled(false);
  131.     orderDateField.setReadOnly(true);
  132.     orderDateLabel.setAlignment(Label.RIGHT);
  133.     orderDateLabel.setFont(new Font("Serif", 1, 12));
  134.     orderDateLabel.setForeground(Color.yellow);
  135.     orderDateLabel.setText(res.getString("Order_Date"));
  136.  
  137.     shipDateLabel.setAlignment(Label.RIGHT);
  138.     shipDateLabel.setFont(new Font("Serif", 1, 12));
  139.     shipDateLabel.setForeground(Color.yellow);
  140.     shipDateLabel.setText(res.getString("Ship_Date"));
  141.     shipDateField.setColumnName("shipDate");
  142.     shipDateField.setFont(new Font("Dialog", 1, 12));
  143.     shipDateField.setBackground(new Color(231, 231, 232));
  144.  
  145.  
  146.     orderNumberLabel.setAlignment(Label.RIGHT);
  147.     orderNumberLabel.setFont(new Font("Serif", 1, 12));
  148.     orderNumberLabel.setForeground(Color.yellow);
  149.     orderNumberLabel.setText(res.getString("Tracking_Number"));
  150.     orderItemsPanel.setBackground(new Color(0, 0, 74));
  151.     orderItemsPanel.setBevelInner(BevelPanel.FLAT);
  152.     orderItemsPanel.setLayout(gridBagLayoutOIPanel);
  153.  
  154.     statusButton.setLabel(res.getString("Show_Status"));
  155.     statusButton.addMouseListener(new OrderTrackApplet_statusButton_mouseAdapter(this));
  156.  
  157.     this.setLayout(gridBagLayoutApplet);
  158.  
  159.     this.add(getStatusPanel, new GridBagConstraints2(0, 0, 1, 1, 1.0, 1.0
  160.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 25, 24));
  161.     getStatusPanel.add(titleGraphic, new GridBagConstraints2(0, 0, 4, 1, 1.0, 1.0
  162.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(-5, 0, 5, 0), -34, -54));
  163.     getStatusPanel.add(orderNumberLabel, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  164.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 8, 3), -11, 4));
  165.     getStatusPanel.add(orderNumberField, new GridBagConstraints2(1, 1, 1, 1, 1.0, 1.0
  166.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -12, 1));
  167.     getStatusPanel.add(statusButton, new GridBagConstraints2(2, 1, 1, 1, 0.0, 0.0
  168.             ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 24, 5));
  169.     this.add(orderItemsPanel, new GridBagConstraints2(0, 1, 2, 1, 1.0, 1.0
  170.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 10, 5), -4, -2));
  171.     orderItemsPanel.add(orderStatusField, new GridBagConstraints2(1, 0, 1, 1, 1.0, 1.0
  172.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), -7, 2));
  173.     orderItemsPanel.add(orderStatusLabel, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  174.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), -6, 1));
  175.     orderItemsPanel.add(orderDateField, new GridBagConstraints2(3, 0, 1, 2, 1.0, 1.0
  176.             ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), -7, 1));
  177.     orderItemsPanel.add(orderDateLabel, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
  178.             ,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 9, 2));
  179.     orderItemsPanel.add(shipDateLabel, new GridBagConstraints2(2, 2, 1, 1, 0.0, 0.0
  180.             ,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 13, 0, 0), 1, -1));
  181.     orderItemsPanel.add(shipDateField, new GridBagConstraints2(3, 2, 1, 1, 1.0, 1.0
  182.             ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), -7, 1));
  183.     orderItemsPanel.add(amountField, new GridBagConstraints2(1, 2, 1, 1, 0.0, 0.0
  184.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), -7, 2));
  185.     orderItemsPanel.add(amountLabel, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
  186.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -6, 0));
  187.  
  188.  
  189.     amountLabel.setAlignment(Label.RIGHT);
  190.     amountLabel.setFont(new Font("Serif", 1, 12));
  191.     amountLabel.setForeground(Color.yellow);
  192.     amountLabel.setText(res.getString("Amount_Paid"));
  193.     amountField.setColumnName("amtPaid");
  194.     amountField.setBackground(new Color(231, 231, 232));
  195.     amountField.setEditInPlace(false);
  196.     amountField.setForeground(Color.black);
  197.     amountField.setFont(new Font("Dialog", 1, 12));
  198.     amountField.setReadOnly(true);
  199.  
  200.  
  201.   }
  202.  
  203.   //Start the applet
  204.   public void start() {
  205.   }
  206.  
  207.   //Stop the applet
  208.   public void stop() {
  209.   }
  210.  
  211.   //Destroy the applet
  212.   public void destroy() {
  213.   }
  214.  
  215.   //Get Applet information
  216.   public String getAppletInfo() {
  217.     return "Applet Information";
  218.   }
  219.  
  220.   //Get parameter info
  221.   public String[][] getParameterInfo() {
  222.     return null;
  223.   }
  224.  
  225.   //Main method
  226.   static public void main(String[] args) {
  227.     OrderTrackApplet applet = new OrderTrackApplet();
  228.     applet.isStandalone = true;
  229.     DecoratedFrame frame = new DecoratedFrame();
  230.     frame.add(applet, BorderLayout.CENTER);
  231.     applet.init();
  232.     applet.start();
  233.     frame.pack();
  234.     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  235.     frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
  236.     frame.setVisible(true);
  237.   }
  238.  
  239.  
  240.   private void initData() {
  241.  
  242.     // Connect to the database and retrieve data set from DataModule
  243.     try {
  244.         OrderTrackDataModule dataModule = OrderTrackDataModule.getDataModule();
  245.         dataModule.dbConnect();  // Makes a connection to the database
  246.         qdsPOrders = dataModule.getOrdersDataSet();
  247.         pRow = dataModule.getOrderNumParameterRow();
  248.     }
  249.     catch (DataSetException ex) {
  250.         ex.printStackTrace();
  251.     }
  252.   }
  253.  
  254.   void statusButton_mouseClicked(MouseEvent e) {
  255.       try {
  256.          // Be sure the value typed in is committed to the field
  257.          orderNumberField.endEdit();
  258.          // Set the ORDERTRACKNUM parameter to the value entered in the field
  259.          pRow.setString("ORDERTRACKNUM", orderNumberField.getText());
  260.          // Get the data for that record
  261.          qdsPOrders.executeQuery();
  262.  
  263.          // Associate each result field with the dataset
  264.          orderStatusField.setDataSet(qdsPOrders);
  265.          orderDateField.setDataSet(qdsPOrders);
  266.          shipDateField.setDataSet(qdsPOrders);
  267.          amountField.setDataSet(qdsPOrders);
  268.      }
  269.       catch (Exception ex) {
  270.             ex.printStackTrace();
  271.       }
  272.   }
  273.  
  274. } // END class OrderTrackApplet
  275.  
  276. class OrderTrackApplet_statusButton_mouseAdapter extends java.awt.event.MouseAdapter {
  277.   OrderTrackApplet adaptee;
  278.  
  279.   OrderTrackApplet_statusButton_mouseAdapter(OrderTrackApplet adaptee) {
  280.     this.adaptee = adaptee;
  281.   }
  282.  
  283.   public void mouseClicked(MouseEvent e) {
  284.     adaptee.statusButton_mouseClicked(e);
  285.   }
  286. }
  287.  
  288.  
  289.