home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / DBServ / SAMPLES / SAMPLES.ZIP / PhoneBook / PHONEBASEAPPJDBC.JAVA < prev    next >
Encoding:
Java Source  |  1997-02-21  |  27.3 KB  |  708 lines

  1. /**************************************************************************************************
  2. *
  3. *  Class name:  PhoneBaseAppJDBC
  4. *     Purpose:  This application accesses the employee table and demonstrates basic database
  5. *               navigation and functionality (e.g., Add Save, First, Next)
  6. *
  7. *     Imports:  java.applet.Applet;
  8. *               java.util.Properties;
  9. *               java.lang.Thread;
  10. *               java.lang.String;
  11. *               java.awt.*
  12. *               symjava.sql.*
  13. *               java.io.*
  14. *
  15. *  Methods include:  public boolean handleEvent(Event event)
  16. *                     public void init()
  17. *                     public void paint(Graphics g)
  18. *                     public void stoplight()
  19. *
  20. *
  21. * Additional Notes:
  22. * THIS SOFTWARE HAS BEEN COMPILED AND EXECUTED SUCCESSFULLY IN SPECIFIC SYMANTEC
  23. * ENVIRONMENTS, AND IS BEING PROVIDED ONLY AS SAMPLE CODE.
  24. *
  25. * SYMANTEC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
  26. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SYMANTEC SHALL NOT
  28. * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING
  29. * THIS SOFTWARE OR ITS DERIVATIVES.
  30. *
  31. *  Please see the Sample Code Configuration  item in the Read Me file for additional
  32. *  information about the sample database used in this applet.
  33. *
  34. * Copyright (c) 1996 Symantec.  All Rights Reserved.
  35. *
  36. ***************************************************************************************************/
  37.  
  38. import java.applet.Applet;
  39. import java.awt.*;
  40. import java.util.Properties;
  41. import java.lang.Thread;
  42. import java.lang.String;
  43. import symjava.sql.*;
  44.  
  45. public class PhoneBaseAppJDBC extends java.applet.Applet {
  46.  
  47.     // DECLARE CONTROLS
  48.     private boolean first = false, good_connection = false;
  49.     private Color current_color = Color.white;
  50.     private String dbaw_driver_name = "symantec.itools.db.jdbc.Driver";
  51.     private String server_url = "jdbc:dbaw://localhost:8889/Watcom/SQL Anywhere 5.0 Sample/SQL Anywhere";
  52.  
  53.     private String db_name = "employee";
  54.     private String first_SQL = "emp_lname";
  55.     private String last_SQL = "emp_fname";
  56.     private String dept_SQL = "dept_id";
  57.     private String phone_SQL = "phone";
  58.     private String site_SQL = "city";
  59.     private String zip_SQL = "zip_code";
  60.     private int max_rs_width = 15;
  61.     private int max_wait_connect = 60;
  62.     private Font f = new Font("default", Font.PLAIN, 12);
  63.     private Font g = new Font("Courier", Font.PLAIN, 13);
  64.  
  65.     // UI (User Interface) and Thread Objects
  66.     Button searchbutton, clearbutton;
  67.     Checkbox quick_search;
  68.     Choice deptchoice, sitechoice, zipchoice;
  69.     Image go_image, stop_image;
  70.     Label firstlabel, lastlabel, deptlabel, sitelabel;
  71.     Label ziplabel, statuslabel, messagelabel, widthlabel, waitconnlabel;
  72.     TextArea output;
  73.     TextField firstfield, lastfield, passfield, waitfield, widthfield, waitconnfield;
  74.     Thread kicker = null;
  75.  
  76.     // JDBC Objects
  77.     Connection server;
  78.     Driver dbaw_driver;
  79.     DriverManager dmanager;
  80.     Properties props = new Properties();
  81.     ResultSet rs;
  82.     Statement stmt;
  83.  
  84.     public void init() {
  85.         // Set the font for everything but output
  86.         this.setFont(f);
  87.  
  88.         // Initialize Background and Text Color
  89.         this.setBackground(Color.white);
  90.         this.setForeground(Color.red);
  91.  
  92.         super.init();
  93.  
  94.         // Initialize Buttons
  95.         searchbutton = new Button("Search for Extension");
  96.         clearbutton = new Button("Clear Form");
  97.  
  98.         // Initialize CheckBox
  99.         quick_search = new Checkbox("Name Search");
  100.         quick_search.setState(true);
  101.  
  102.         // Initialize Choices
  103.         deptchoice = new Choice();
  104.         deptchoice.addItem("All");
  105.         deptchoice.select(0);
  106.         deptchoice.disable();
  107.  
  108.         sitechoice = new Choice();
  109.         sitechoice.addItem("All");
  110.         sitechoice.select(0);
  111.         sitechoice.disable();
  112.  
  113.         zipchoice = new Choice();
  114.         zipchoice.addItem("All");
  115.         zipchoice.select(0);
  116.         zipchoice.disable();
  117.  
  118.         // Initialize Images
  119.         go_image = Toolkit.getDefaultToolkit().getImage("go_image.gif");
  120.         stop_image = Toolkit.getDefaultToolkit().getImage("stop_image.gif");
  121.  
  122.         // Initialize Labels
  123.         firstlabel = new Label("First Name:");
  124.         lastlabel = new Label("Last Name:");
  125.         deptlabel = new Label("Department:");
  126.         sitelabel = new Label("City:");
  127.         ziplabel = new Label("Zip Code:");
  128.         statuslabel = new Label("Status:");
  129.         messagelabel = new Label("Feedback:");
  130.         widthlabel = new Label("Text Width:");
  131.         waitconnlabel = new Label("Wait to Connect (in sec):");
  132.  
  133.         // Initialize Properties
  134.         props.put("user","dba");
  135.         props.put("password","sql");
  136.  
  137.         // Initialize TextArea
  138.         output = new TextArea();
  139.         output.setEditable(false);
  140.         output.setFont(g);
  141.  
  142.         // Initialize TextFields
  143.         widthfield = new TextField();
  144.         widthfield.setBackground(current_color);
  145.         widthfield.setText(String.valueOf(max_rs_width));
  146.  
  147.         waitconnfield = new TextField();
  148.         waitconnfield.setBackground(current_color);
  149.         waitconnfield.setText(String.valueOf(max_wait_connect));
  150.  
  151.         firstfield = new TextField();
  152.         firstfield.setBackground(current_color);
  153.  
  154.         lastfield = new TextField();
  155.         lastfield.setBackground(current_color);
  156.  
  157.         passfield = new TextField();
  158.         passfield.setBackground(current_color);
  159.         passfield.disable();
  160.  
  161.         waitfield = new TextField();
  162.         waitfield.setBackground(current_color);
  163.         waitfield.disable();
  164.         waitfield.setText("Ready.");
  165.  
  166.         //{{INIT_CONTROLS
  167.         setLayout(null);
  168.  
  169.         // Add Checkbox
  170.         add(quick_search);
  171.         quick_search.reshape(insets().left+85, insets().top+5, 100, 20);
  172.  
  173.         // Add Width
  174.         add(widthlabel);
  175.         widthlabel.reshape(insets().left+195, insets().top+7, 75, 20);
  176.         add(widthfield);
  177.         widthfield.reshape(insets().left+270, insets().top+7, 40, 20);
  178.  
  179.         // Add WaitConn
  180.         add(waitconnlabel);
  181.         waitconnlabel.reshape(insets().left+312, insets().top+7, 147, 20);
  182.         add(waitconnfield);
  183.         waitconnfield.reshape(insets().left+460, insets().top+7, 40, 20);
  184.  
  185.         // Add First Name
  186.         add(firstlabel);
  187.         firstlabel.reshape(insets().left+2, insets().top+40, 80, 20);
  188.         add(firstfield);
  189.         firstfield.reshape(insets().left+85, insets().top+40, 160, 20);
  190.         firstfield.requestFocus();
  191.  
  192.         // Add Last Name
  193.         add(lastlabel);
  194.         lastlabel.reshape(insets().left+250, insets().top+40, 80, 20);
  195.         add(lastfield);
  196.         lastfield.reshape(insets().left+335, insets().top+40, 165, 20);
  197.  
  198.         // Add Department
  199.         add(deptlabel);
  200.         deptlabel.reshape(insets().left+2, insets().top+65, 80, 20);
  201.         add(deptchoice);
  202.         deptchoice.reshape(insets().left+85, insets().top+65, 160, 20);
  203.  
  204.         // Add Site
  205.         add(sitelabel);
  206.         sitelabel.reshape(insets().left+250, insets().top+65, 80, 20);
  207.         add(sitechoice);
  208.         sitechoice.reshape(insets().left+335, insets().top+65, 165, 20);
  209.  
  210.         // Add zip
  211.         add(ziplabel);
  212.         ziplabel.reshape(insets().left+2, insets().top+90, 80, 20);
  213.         add(zipchoice);
  214.         zipchoice.reshape(insets().left+85, insets().top+90, 160, 20);
  215.  
  216.         // Add Search for Extension Button
  217.         add(searchbutton);
  218.         searchbutton.reshape(insets().left+260, insets().top+90, 140, 20);
  219.  
  220.         // Add Clear Button
  221.         add(clearbutton);
  222.         clearbutton.reshape(insets().left+405, insets().top+90, 95, 20);
  223.  
  224.         // Add Waitfield
  225.         add(statuslabel);
  226.         statuslabel.reshape(insets().left+2, insets().top+115, 80, 20);
  227.         add(waitfield);
  228.         waitfield.reshape(insets().left+85, insets().top+115, 415, 20);
  229.  
  230.         // Add Passfield
  231.         add(messagelabel);
  232.         messagelabel.reshape(insets().left+2, insets().top+140, 80, 20);
  233.         add(passfield);
  234.         passfield.reshape(insets().left+85, insets().top+140, 415, 20);
  235.  
  236.         // Add Output
  237.         add(output);
  238.         output.reshape(insets().left+15, insets().top+165, 485, 335);
  239.  
  240.         // Show opening messages
  241.         opening();
  242.  
  243.         // Display stop light
  244.         stoplight();
  245.         repaint();
  246.  
  247.         show();
  248.         //}}
  249.     }
  250.  
  251.     // add_choices()
  252.     final void add_choices() {
  253.         searchbutton.disable();
  254.         stoplight();                                            // show red light
  255.  
  256.         // Create statement for choices
  257.         try {
  258.             // create a statement to be executed from the connection
  259.             stmt = server.createStatement();
  260.         }
  261.         catch (SQLException stmt_error) {
  262.             passfield.setText("Could not create statement for department!");
  263.             sleep();
  264.         }
  265.  
  266.         // Add department choice
  267.         try {
  268.             waitfield.setText("Please wait while PhoneBase is loading...");
  269.             passfield.setText("Opening database '" + db_name + "'");
  270.  
  271.             // Get result set
  272.             rs = stmt.executeQuery("SELECT DISTINCT " + dept_SQL + " FROM "
  273.                 + db_name + " ORDER BY " + dept_SQL);
  274.  
  275.             passfield.setText("Adding department choices...");
  276.  
  277.             // Grab the first record.  If it's null, get the next record
  278.             // (Since they were sorted, all the null are on the top)
  279.             // then add it to the choice box
  280.             rs.next();
  281.             while (rs.getString(1) == null) rs.next();
  282.             deptchoice.addItem(rs.getString(1));
  283.  
  284.             // Continue to grab records and add them to the choice
  285.             while (rs.next()) { deptchoice.addItem(rs.getString(1)); }
  286.             deptchoice.enable();
  287.         }
  288.         catch (SQLException next_error) {
  289.             passfield.setText("Problem with department choice!");
  290.             sleep();
  291.         }
  292.  
  293.         // Add site choice
  294.         try {
  295.             // Get result set
  296.             rs = stmt.executeQuery("SELECT DISTINCT " + site_SQL + " FROM "
  297.                 + db_name + " ORDER BY " + site_SQL
  298.                 );
  299.  
  300.             passfield.setText("Adding site choices...");
  301.  
  302.             // Grab the first record.  If it's null, get the next record
  303.             // (Since they were sorted, all the null are on the top)
  304.             // then add it to the choice box
  305.             rs.next();
  306.             while (rs.getString(1) == null) rs.next();
  307.             sitechoice.addItem(rs.getString(1));
  308.  
  309.             // Continue to grab records and add them to the choice
  310.             while (rs.next()) { sitechoice.addItem(rs.getString(1)); }
  311.             sitechoice.enable();
  312.         }
  313.         catch (SQLException next_error) {
  314.             passfield.setText("Problem with site choice!");
  315.             sleep();
  316.         }
  317.  
  318.         // Add zip choice
  319.         try {
  320.             // Get result set
  321.             rs = stmt.executeQuery("SELECT DISTINCT " + zip_SQL + " FROM "
  322.                 + db_name + " ORDER BY " + zip_SQL);
  323.  
  324.             passfield.setText("Adding zip choice...");
  325.  
  326.             // Grab the first record.  If it's null, get the next record
  327.             // (Since they were sorted, all the null are on the top)
  328.             // then add it to the choice box
  329.             rs.next();
  330.             while (rs.getString(1) == null) rs.next();
  331.             zipchoice.addItem(rs.getString(1));
  332.  
  333.             // Continue to grab records and add them to the choice
  334.             while (rs.next()) { zipchoice.addItem(rs.getString(1)); }
  335.             zipchoice.enable();
  336.         }
  337.         catch (SQLException next_error) {
  338.             passfield.setText("Problem with zip choice!");
  339.             sleep();
  340.         }
  341.  
  342.         // Close the statement
  343.         try { rs.close(); stmt.close(); }
  344.         catch (SQLException close_error) {
  345.             passfield.setText("Could not close statement/resultset for zip");
  346.             sleep();
  347.         }
  348.  
  349.         // Reset the UI
  350.         waitfield.setText("Ready.");
  351.         passfield.setText("");
  352.         searchbutton.enable();
  353.         repaint();                                              // show green light
  354.     }
  355.  
  356.     // close_server()
  357.     final void close_server() {
  358.         passfield.setText("Closing server " + server_url + "...");
  359.         try {
  360.             server.close();
  361.             passfield.setText("Connection closed safely!");
  362.  
  363.             good_connection = false;
  364.         }
  365.         catch (Exception close_error) {
  366.             passfield.setText("Could not close " + server_url);
  367.             sleep();
  368.         }
  369.     }
  370.  
  371.     // connect_server()
  372.     final void connect_server() {
  373.         waitfield.setText("Busy.");
  374.         passfield.setText("Opening server " + server_url + "...");
  375.  
  376.         // set the timeout so that server closes if fail to connect
  377.         dmanager.setLoginTimeout(Integer.valueOf(waitconnfield.getText()).intValue());
  378.  
  379.         try {
  380.             searchbutton.disable();
  381.             widthfield.disable();
  382.             waitconnfield.disable();
  383.  
  384.             // create a specific driver for use with JDBC
  385.             dbaw_driver = (Driver)Class.forName(dbaw_driver_name).newInstance();
  386.             // connect with the driver
  387.             server = dbaw_driver.connect(server_url, props);
  388.             passfield.setText("Opening server " + server_url + "... Connection successful!");
  389.             good_connection = true;
  390.         }
  391.         catch (InstantiationException e) { passfield.setText(e.getMessage()); }
  392.         catch (ClassNotFoundException e) { passfield.setText(e.getMessage()); }
  393.         catch (IllegalAccessException e) { passfield.setText(e.getMessage()); }
  394.         catch (SQLException open_error) {
  395.             passfield.setText("Could not open server " + server_url);
  396.             waitfield.setText("Ready.");
  397.             searchbutton.enable();
  398.             widthfield.enable();
  399.             waitconnfield.enable();
  400.         }
  401.     }
  402.  
  403. // db_search()
  404.     final void db_search() {
  405.         int counter = 0;
  406.         String temp_string1, temp_string2;
  407.         String padding = new String("                                                   ");
  408.  
  409.         // Show Status
  410.         waitfield.setText("Please wait while PhoneBase is loading...");
  411.  
  412.         // Print the results
  413.         String searchfirst = new String(firstfield.getText());
  414.         String searchlast = new String(lastfield.getText());
  415.  
  416.         try {
  417.             passfield.setText("Opening database '" + db_name + "'");
  418.             // create a statement to be executed from the connection
  419.             stmt = server.createStatement();
  420.  
  421.             try {
  422.                 // fetch the new value of Text Width
  423.                 max_rs_width = Integer.valueOf(widthfield.getText()).intValue();
  424.                 // get results
  425.                 rs = stmt.executeQuery(generate_SQL());
  426.  
  427.                 output.setText("              PhoneBase Search Result\n");
  428.                 output.appendText("========================================================\n");
  429.  
  430.                 if (rs.next()) {                     // grab first record
  431.                     // add padding for textwidth
  432.                     temp_string1 = new String(rs.getString(1).concat(padding));
  433.                     temp_string1 = temp_string1.substring(0, max_rs_width);
  434.                     temp_string2 = new String(rs.getString(2).concat(padding));
  435.                     temp_string2 = temp_string2.substring(0, max_rs_width);
  436.  
  437.                     output.appendText("Located:\n");
  438.                     output.appendText("   " + temp_string2 + ", " + temp_string1
  439.                         + " at extension " + rs.getString(3).substring(6) + "\n");
  440.                     counter++;
  441.  
  442.                     // continue to grab records
  443.                     while(rs.next()) {
  444.                         // add padding for textwidth
  445.                         temp_string1 = rs.getString(1).concat(padding);
  446.                         temp_string1 = temp_string1.substring(0, max_rs_width);
  447.                         temp_string2 = rs.getString(2).concat(padding);
  448.                         temp_string2 = temp_string2.substring(0, max_rs_width);
  449.  
  450.                         output.appendText("   " + temp_string2 + ", " + temp_string1
  451.                             + " at extension " + rs.getString(3).substring(6) + "\n");
  452.                         counter++;
  453.                     }
  454.                     output.appendText("\n" + counter + " hit(s) found.\n");
  455.                 }
  456.             }
  457.             catch (SQLException next_error) {
  458.                 passfield.setText("Problem with executing multiple statements!");
  459.                 sleep();
  460.             }
  461.  
  462.             rs.close();
  463.             stmt.close();
  464.         }
  465.         catch (Exception filter_error) {
  466.             passfield.setText("Could not create/close statement!");
  467.             sleep();
  468.         }
  469.  
  470.         if (counter == 0) output.appendText("\nNo hits found.\n\n");
  471.         output.appendText("========================================================\n");
  472.  
  473.         // Reset the UI
  474.         searchbutton.enable();
  475.         widthfield.enable();
  476.         waitconnfield.enable();
  477.         waitfield.setText("Ready.");
  478.         passfield.setText("");
  479.  
  480.         repaint();                                                  // show green light
  481.     }
  482.  
  483.     // generate_SQL()
  484.     final String generate_SQL() {
  485.         // stuff needed for this method
  486.         waitfield.setText("Search initiated...");
  487.         String select = new String("SELECT " + first_SQL + ", " + last_SQL + ", " + phone_SQL + " ");
  488.         String from = new String("FROM " + db_name + " ");
  489.         boolean first_exist = false, last_exist = false, not_first_one = false;
  490.         boolean dept_exist = false, site_exist = false, zip_exist = false;
  491.         int wild_return = has_wildcard();
  492.  
  493.         // if there is something in these textfields and choices, then they exist
  494.         if (firstfield.getText().length() != 0) first_exist = true;
  495.         if (lastfield.getText().length() != 0) last_exist = true;
  496.         if (deptchoice.getSelectedIndex() != 0) dept_exist = true;
  497.         if (sitechoice.getSelectedIndex() != 0) site_exist = true;
  498.         if (zipchoice.getSelectedIndex() != 0) zip_exist = true;
  499.  
  500.         // if the textfield only has '*', then they don't exist
  501.         // it would be redundant to have firstfield to contain 'bob' and lastfield
  502.         // to contain '*' when you could say only firstfield has 'bob'
  503.         if (firstfield.getText().compareTo("*") == 0) first_exist = false;
  504.         if (lastfield.getText().compareTo("*") == 0) last_exist = false;
  505.  
  506.         // if any of the components exist, then do a conditional search (where clause)
  507.         if (first_exist || last_exist || dept_exist || site_exist || zip_exist) {
  508.             from = from.concat("WHERE");
  509.  
  510.             // if firstfield exists and it contains no '*', do simple "where a='b'"
  511.             // statement
  512.             if ( (first_exist) && ((wild_return == 0) || (wild_return == 2)) ){
  513.                 not_first_one = true;
  514.                 from = from.concat(" " + first_SQL + " = '" + firstfield.getText() + "'");
  515.             }
  516.             // else use "where a LIKE 'b%'" statement
  517.             else if ( (first_exist) && ((wild_return == 1) || (wild_return == 3)) ) {
  518.                 not_first_one = true;
  519.                 from = from.concat(" " + first_SQL + " LIKE '"
  520.                     + (firstfield.getText()).replace('*', '%').replace('?', '_') + "'");
  521.             }
  522.  
  523.             // if lastfield exists and it contains no '*', do simple "where a='b'"
  524.             // statement
  525.             if ( (last_exist) && ((wild_return == 0) || (wild_return == 1)) ) {
  526.                 if (not_first_one) { from = from.concat(" AND"); }
  527.                 from = from.concat(" " + last_SQL + " = '" + lastfield.getText() + "'");
  528.             }
  529.             // else use "where a LIKE 'b%'" or "where a LIKE 'b_'" statement
  530.             else if ( (last_exist) && ((wild_return == 2) || (wild_return == 3)) ) {
  531.                 if (not_first_one) { from = from.concat(" AND"); }
  532.                 not_first_one = true;
  533.                 from = from.concat(" " + last_SQL + " LIKE '"
  534.                     + (lastfield.getText()).replace('*', '%').replace('?', '_') + "'");
  535.             }
  536.  
  537.             // for rest of choices, do simple "where a = 'b'" statement
  538.             if (dept_exist) {
  539.                 if (not_first_one) { from = from.concat(" AND"); }
  540.                 from = from.concat(" " + dept_SQL + " = '" + deptchoice.getSelectedItem() + "'");
  541.             }
  542.             if (site_exist) {
  543.                 if (not_first_one) { from = from.concat(" AND"); }
  544.                 from = from.concat(" " + site_SQL + " = '" + sitechoice.getSelectedItem() + "'");
  545.             }
  546.             if (zip_exist) {
  547.                 if (not_first_one) { from = from.concat(" AND"); }
  548.                 from = from.concat(" " + zip_SQL + " = '" + zipchoice.getSelectedItem() + "'");
  549.             }
  550.         }
  551.         // assemble and return the SQL statement
  552.         return (select + from);
  553.     }
  554.  
  555.     // has_wildcard()
  556.     final int has_wildcard() {
  557.         int num_of_wildcard = 0;
  558.  
  559.         // if the textfield has wildcard, set it equal to a number
  560.         // 0 = none, 1 = first, 2 = last, 3 = first and last
  561.         if ((firstfield.getText()).indexOf("*", 0) != -1) { num_of_wildcard = 1; }
  562.         else if ((firstfield.getText()).indexOf("?", 0) != -1) { num_of_wildcard = 1; }
  563.         if ((lastfield.getText()).indexOf("*", 0) != -1) {
  564.             if (num_of_wildcard == 1) num_of_wildcard = 3;
  565.             else num_of_wildcard = 2;
  566.         }
  567.         else if ((lastfield.getText()).indexOf("?", 0) != -1) {
  568.             if (num_of_wildcard == 1) num_of_wildcard = 3;
  569.             else num_of_wildcard = 2;
  570.         }
  571.         return num_of_wildcard;
  572.     }
  573.  
  574.     // is_empty()
  575.     final boolean is_empty() {
  576.         // are the textfields empty?
  577.         if (((firstfield.getText()).length() == 0) && ((lastfield.getText()).length() == 0))
  578.             return true;
  579.         else return false;
  580.     }
  581.  
  582.     // opening()
  583.     final void opening() {
  584.         output.setText("Welcome to PhoneBaseJDBC-Watcom '96 Build 17\n");
  585.         output.appendText("========================================================\n");
  586.         output.appendText("This program contains:\n");
  587.         output.appendText("    - Data-aware choice components.\n");
  588.         output.appendText("    - Supports wildcard searches via '*'.\n");
  589.         output.appendText("    - Supports single-place wildcard searches via '?'.\n");
  590.         output.appendText("    - Text Width adjustments.\n");
  591.         output.appendText("========================================================\n");
  592.     }
  593.  
  594.     // paint()
  595.     public void paint(Graphics g) {
  596.         g.drawImage(go_image, 15, 5, this);
  597.     }
  598.  
  599.     // sleep()
  600.     final void sleep() {
  601.         waitfield.setText("Exception caught! Please notify maintenance of exception below.");
  602.         firstfield.disable();
  603.         this.disable();
  604.         for (int i = 0; i < 3; i++) i = 1;
  605.     }
  606.  
  607.     // stoplight()
  608.     public void stoplight() {
  609.         Graphics gr = this.getGraphics();
  610.         gr.clearRect(15, 5, 28, 34);
  611.         gr.drawImage(stop_image, 15, 5, null);
  612.     }
  613.  
  614.     // handleEvent()
  615.     public boolean handleEvent(Event event) {
  616.         Object evt = event.target;
  617.  
  618.         // Display Status
  619.         this.showStatus("Symantec Corp., 1996");
  620.  
  621.         if (event.id == Event.KEY_PRESS) {
  622.             // tabbing order
  623.             if (event.key == 9) {
  624.                 if (evt == firstfield) {lastfield.requestFocus();}
  625.                 else if ((evt == lastfield) && (deptchoice.isEnabled())) {
  626.                     deptchoice.requestFocus();
  627.                 }
  628.                 else if ((evt == lastfield) && (!deptchoice.isEnabled())) {
  629.                     firstfield.requestFocus();
  630.                 }
  631.                 else if (evt == deptchoice) {sitechoice.requestFocus();}
  632.                 else if (evt == sitechoice) {zipchoice.requestFocus();}
  633.                 else if (evt == zipchoice) {searchbutton.requestFocus();}
  634.                 else if (evt == searchbutton) {clearbutton.requestFocus();}
  635.                 else if (evt == clearbutton) {firstfield.requestFocus();}
  636.                 else if (evt == output) {firstfield.requestFocus(); }
  637.                 else { InterruptedException e; return false;}
  638.             }
  639.             // if press enter and textfield exists, do search
  640.             else if ((event.key == 10) && (!is_empty())) {
  641.                 stoplight();
  642.                 if (good_connection) {db_search();}     // if connection exist, do search
  643.                 else {                                  // else, start the connection
  644.                     connect_server();
  645.                     if (good_connection) {db_search();}
  646.                 }
  647.             }
  648.             else return super.handleEvent(event);
  649.             return true;
  650.         }
  651.         // clear or reset everything
  652.         else if ((event.id == Event.ACTION_EVENT) && (evt instanceof Button)) {
  653.             if (evt == clearbutton) {
  654.                 firstfield.setText("");
  655.                 lastfield.setText("");
  656.                 deptchoice.select(0);
  657.                 sitechoice.select(0);
  658.                 zipchoice.select(0);
  659.                 firstfield.requestFocus();
  660.             }
  661.             // if click enter and textfield exists, do search
  662.             else if ((evt == searchbutton) && (!is_empty())) {
  663.                 stoplight();
  664.                 if (good_connection) {db_search();}     // if connection exist, do search
  665.                 else {                                  // else, start the connection
  666.                     connect_server();
  667.                     if (good_connection) {db_search();}
  668.                 }
  669.             }
  670.             else { InterruptedException e; return false; }
  671.             return true;
  672.         }
  673.         else if ((event.id == Event.ACTION_EVENT) && (evt instanceof Checkbox)) {
  674.             // if checkbox is unchecked, add choices
  675.             if ((evt == quick_search) && (quick_search.getState() == false)) {
  676.                 quick_search.setState(false);
  677.                 if (!good_connection) { connect_server();}   // if connection exist, do search
  678.                 add_choices();                               // get choice information
  679.                 firstfield.requestFocus();
  680.             }
  681.             // if checkbox is checked, disable choices
  682.             if ((evt == quick_search) && (quick_search.getState() == true)) {
  683.                 quick_search.setState(true);
  684.                 searchbutton.disable();
  685.                 // reset choices to 'all'
  686.                 deptchoice.select(0);
  687.                 deptchoice.disable();
  688.                 sitechoice.select(0);
  689.                 sitechoice.disable();
  690.                 zipchoice.select(0);
  691.                 zipchoice.disable();
  692.  
  693.                 searchbutton.enable();
  694.             }
  695.             else { InterruptedException e; return false; }
  696.             return true;
  697.         }
  698.         else if (event.id == Event.WINDOW_DESTROY) {
  699.             close_server();
  700.             kicker = null;
  701.             super.stop();
  702.             System.exit(0);
  703.             return true;
  704.         }
  705.         else return super.handleEvent(event);
  706.     }
  707. }
  708.