home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-12-06 | 11.5 KB | 414 lines |
- //******************************************************************************
- // simplerdo.java: Applet
- //
- //******************************************************************************
- import java.applet.*;
- import java.awt.*;
- import simplerdoframe;
-
- import msrdo20.*;
- import com.ms.com.*;
-
- // SimpleForm is the data entry form for the sample
- class SimpleForm extends Panel
- {
- // Access to the data
- _rdoResultset m_resultset;
-
- // The fields in the form
- TextField field1;
- TextField field2;
- TextField field3;
- TextField field4;
- TextField field5;
- TextField field6;
- Checkbox field7;
-
- // The names of the resultset columns
- Variant name1;
- Variant name2;
- Variant name3;
- Variant name4;
- Variant name5;
- Variant name6;
- Variant name7;
-
- // Create the form
- SimpleForm(_rdoResultset r)
- {
- // Set the recordset
- m_resultset = r;
-
- // Create panels for the labels and fields
- Panel labels = new Panel();
- Panel fields = new Panel();
-
- // Set those panels as a grid, one column wide
- labels.setLayout(new GridLayout(0, 1));
- fields.setLayout(new GridLayout(0, 1));
-
- // Set the form as labels to the left, fields to the right
- setLayout(new FlowLayout());
- add(labels);
- add(fields);
-
- // Set the first label and field
- // Create the label and add it into the form
- labels.add(new Label("Full Name"));
- // Create the field and add it into the form
- fields.add(field1 = new TextField(25));
- // Disable the field since the access is read-only
- field1.disable();
- // Create the field name for use with getItem
- name1 = new Variant();
- name1.putString("Name");
-
- // Repeat for the other labels and fields
- labels.add(new Label("E-Mail Name"));
- fields.add(field2 = new TextField(10));
- field2.disable();
- name2 = new Variant();
- name2.putString("Email");
-
- labels.add(new Label("Phone Extension"));
- fields.add(field3 = new TextField(12));
- field3.disable();
- name3 = new Variant();
- name3.putString("Phone");
-
- labels.add(new Label("Office Location"));
- fields.add(field4 = new TextField(15));
- field4.disable();
- name4 = new Variant();
- name4.putString("Location");
-
- labels.add(new Label("Manager"));
- fields.add(field5 = new TextField(10));
- field5.disable();
- name5 = new Variant();
- name5.putString("Manager");
-
- labels.add(new Label("Date of Hire"));
- fields.add(field6 = new TextField(10));
- field6.disable();
- name6 = new Variant();
- name6.putString("HireDate");
-
- labels.add(new Label("Certified"));
- fields.add(field7 = new Checkbox());
- field7.disable();
- name7 = new Variant();
- name7.putString("Certified");
-
- }
-
- // Show the data in the form
- void showData()
- {
- // Get the columns in the resultset
- rdoColumns columns = m_resultset.getrdoColumns();
- _rdoColumn c;
-
- // Create a Variant to get the value of each column
- Variant value;
-
- // Get the first column
- c = columns.getItem(name1);
- // Get its value
- value = c.getValue();
- // Set the field in the form
- field1.setText(value.toString());
-
- // Repeat for the other columns
- c = columns.getItem(name2);
- value = c.getValue();
- field2.setText(value.toString());
-
- c = columns.getItem(name3);
- value = c.getValue();
- field3.setText(value.toString());
-
- c = columns.getItem(name4);
- value = c.getValue();
- field4.setText(value.toString());
-
- c = columns.getItem(name5);
- value = c.getValue();
- field5.setText(value.toString());
-
- c = columns.getItem(name6);
- value = c.getValue();
- field6.setText(value.toString());
-
- c = columns.getItem(name7);
- value = c.getValue();
- field7.setState(value.getBoolean());
- }
- }
-
-
- //==============================================================================
- // Main Class for applet simplerdo
- //
- //==============================================================================
- public class simplerdo extends Applet
- {
- // RDO objects
- // The connection to the ODBC data source
- public static _rdoConnection m_IConnection;
- // The resultset from the query
- public static _rdoResultset m_IResultSet;
-
- // Toolbar
- Panel m_toolbar;
- Button m_first;
- Button m_prev;
- Button m_next;
- Button m_last;
-
- // Data Entry Form
- SimpleForm m_form;
-
- // STANDALONE APPLICATION SUPPORT:
- // m_fStandAlone will be set to true if applet is run standalone
- //--------------------------------------------------------------------------
- boolean m_fStandAlone = false;
-
-
-
- // STANDALONE APPLICATION SUPPORT
- // The main() method acts as the applet's entry point when it is run
- // as a standalone application. It is ignored if the applet is run from
- // within an HTML page.
- //--------------------------------------------------------------------------
- public static void main(String args[])
- {
- // Create Toplevel Window to contain applet simplerdo
- //----------------------------------------------------------------------
- simplerdoframe frame = new simplerdoframe("simplerdo");
-
- // Must show Frame before we size it so insets() will return valid values
- //----------------------------------------------------------------------
- frame.show();
- frame.hide();
- frame.resize(frame.insets().left + frame.insets().right + 320,
- frame.insets().top + frame.insets().bottom + 240);
-
- // The following code starts the applet running within the frame window.
- // It also calls GetParameters() to retrieve parameter values from the
- // command line, and sets m_fStandAlone to true to prevent init() from
- // trying to get them from the HTML page.
- //----------------------------------------------------------------------
- simplerdo applet_simplerdo = new simplerdo();
-
- frame.add("Center", applet_simplerdo);
- applet_simplerdo.m_fStandAlone = true;
- applet_simplerdo.init();
- applet_simplerdo.start();
- frame.show();
- }
-
- // simplerdo Class Constructor
- //--------------------------------------------------------------------------
- public simplerdo()
- {
- // Create the toolbar and add it to the applet
- m_toolbar = new Panel();
- setLayout(new BorderLayout());
- add("North", m_toolbar);
- m_toolbar.add(m_first = new Button("First"));
- m_toolbar.add(m_prev = new Button("Prev"));
- m_toolbar.add(m_next = new Button("Next"));
- m_toolbar.add(m_last = new Button("Last"));
- }
-
- // APPLET INFO SUPPORT:
- // The getAppletInfo() method returns a string describing the applet's
- // author, copyright date, or miscellaneous information.
- //--------------------------------------------------------------------------
- public String getAppletInfo()
- {
- return "Name: simplerdo\r\n" +
- "Created with Microsoft Visual J++ Version 1.0";
- }
-
-
- // The init() method is called by the AWT when an applet is first loaded or
- // reloaded. Override this method to perform whatever initialization your
- // applet needs, such as initializing data structures, loading images or
- // fonts, creating frame windows, setting the layout manager, or adding UI
- // components.
- //--------------------------------------------------------------------------
- public void init()
- {
- // If you use a ResourceWizard-generated "control creator" class to
- // arrange controls in your applet, you may want to call its
- // CreateControls() method from within this method. Remove the following
- // call to resize() before adding the call to CreateControls();
- // CreateControls() does its own resizing.
- //----------------------------------------------------------------------
- resize(320, 240);
-
- }
-
- // Place additional applet clean up code here. destroy() is called when
- // when you applet is terminating and being unloaded.
- //-------------------------------------------------------------------------
- public void destroy()
- {
- }
-
- // simplerdo Paint Handler
- //--------------------------------------------------------------------------
- public void paint(Graphics g)
- {
- }
-
- // The start() method is called when the page containing the applet
- // first appears on the screen. The AppletWizard's initial implementation
- // of this method starts execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void start()
- {
- // Setup Variants for optional parameters
- Variant v1 = new Variant();
- Variant v2 = new Variant();
- Variant v3 = new Variant();
- Variant v4 = new Variant();
- Variant v5 = new Variant();
- Variant v6 = new Variant();
- Variant v7 = new Variant();
-
- // Set optional parameter values
- v1.putInt(PromptConstants.rdDriverNoPrompt);
- v2.putBoolean(false);
- v3.putInt(0);
-
- // Open a connection to the data source
- rdoConnection Connection = new rdoConnection();
- m_IConnection = (_rdoConnection) Connection;
-
- m_IConnection.putConnect("DSN=Sample Database;UID=;PWD=;Database=Sample Database;");
-
- m_IConnection.EstablishConnection(v1, v2, v3);
-
- // Set optional parameters
- v4.putInt(ResultsetTypeConstants.rdOpenKeyset);
- v5.putInt(LockTypeConstants.rdConcurReadOnly);
- v6.putInt(0);
-
- m_IResultSet = (_rdoResultset) m_IConnection.OpenResultset("SELECT * FROM Employees",v4,v5,v6);
-
- // Create the form, passing the resultset
- m_form = new SimpleForm(m_IResultSet);
-
- // Add the form to the applet
- add("Center", m_form);
-
- // Get the first row in the resultset
- m_IResultSet.MoveFirst();
-
- // Display that row
- m_form.showData();
-
- }
-
- // The stop() method is called when the page containing the applet is
- // no longer on the screen. The AppletWizard's initial implementation of
- // this method stops execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void stop()
- {
- // Close the resultset
- m_IResultSet.Close();
- m_IResultSet = null;
-
- // And remove the form
- remove(m_form);
- m_form = null;
- }
-
- public boolean action(Event evt, Object what)
- {
- // Handle click on the First button
- if (evt.target == m_first)
- {
- // Update the status bar, if available
- if (! m_fStandAlone) showStatus ("Getting first record");
-
- // Move to the requested row
- m_IResultSet.MoveFirst();
-
- // Show that row
- m_form.showData();
-
- // Event handled
- return true;
- }
-
- // Handle click on the Prev button
- if (evt.target == m_prev)
- {
- // Update the status bar, if available
- if (! m_fStandAlone) showStatus ("Getting previous record");
-
- // Move to the requested row
- m_IResultSet.MovePrevious();
-
- // Make sure we don't move before BOF
- if (m_IResultSet.getBOF())
- m_IResultSet.MoveFirst();
-
- // Show that row
- m_form.showData();
-
- // Event handled
- return true;
- }
-
- // Handle click on the Next button
- if (evt.target == m_next)
- {
- // Update the status bar, if available
- if (! m_fStandAlone) showStatus ("Getting next record");
-
- // Move to the requested row
- m_IResultSet.MoveNext();
-
- // Make sure we don't move past EOF
- if (m_IResultSet.getEOF())
- {
- Variant v1 = new Variant();
- m_IResultSet.MoveLast(v1);
- }
-
- // Show that row
- m_form.showData();
-
- // Event handled
- return true;
- }
-
- // Handle click on the Last button
- if (evt.target == m_last)
- {
- Variant v1 = new Variant();
- // Update the status bar, if available
- if (! m_fStandAlone) showStatus ("Getting last record");
-
- // Move to the requested row
- m_IResultSet.MoveLast(v1);
-
- // Show that row
- m_form.showData();
-
- // Event handled
- return true;
- }
-
- // Event not handled
- return false;
- }
-
- }
-