home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 34.1 KB | 861 lines |
- /**************************************************************************************************
- * *
- * Class name: customer *
- * Purpose: This application accesses the customer table and demonstrates basic database *
- * navigation and functionality (e.g., Add, Save, First, Next) *
- * *
- * Imports: java.awt.* *
- * java.applet.* *
- * symjava.sql.* *
- * java.io.* *
- * *
- * Methods include: void goTo() *
- * boolean goNext() *
- * boolean goPrevious() *
- * public class customer *
- * class DataBase *
- * public void init() *
- * public boolean handleEvent(Event) *
- * public void start() *
- * public boolean keyDown(Event, int) *
- * void tab(Event) *
- * *
- * Additional Notes: *
- * THIS SOFTWARE HAS BEEN COMPILED AND EXECUTED SUCCESSFULLY IN SPECIFIC SYMANTEC *
- * ENVIRONMENTS, AND IS BEING PROVIDED ONLY AS SAMPLE CODE. *
- * *
- * SYMANTEC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, *
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF *
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SYMANTEC SHALL NOT *
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING *
- * THIS SOFTWARE OR ITS DERIVATIVES. *
- * *
- * Please see the Sample Code Configuration item in the Read Me file for additional *
- * information about the sample database used in this applet. *
- * *
- * Copyright (c) 1996 Symantec. All Rights Reserved. *
- * *
- ***************************************************************************************************/
-
- import java.awt.*;
- import java.applet.*;
- import symjava.sql.*;
- import java.util.*;
- import java.io.*;
-
- class DataBase {
- private String serverUrl;
- // check for connection.
- private boolean isConnection;
- Driver driver;
- Connection server;
- Properties props;
- ResultSet resultSet;
- int firstRec;
- int lastRec;
- // check if the resultSet is in ascending order w/respect to id
- boolean isAscending;
-
-
- DataBase(String hostname, String user, String password) {
- serverUrl = hostname;
- isConnection = false;
- props = new Properties();
- props.put("user", user);
- props.put("password", password);
- resultSet = null;
- isAscending = true;
- firstRec = 0;
- lastRec = 0;
- }
-
- void connectServer(String driver_name) {
- // Use the driver_name driver to connect to the data base server.
- try {
- driver =
- (symjava.sql.Driver)Class.forName(driver_name).newInstance();
- server = driver.connect(serverUrl, props);
- }
- catch (SQLException e) {
- System.out.println("Exception from DataBase.connectServer() : " +
- e.getMessage());
- }
- catch (InstantiationException e) {
- System.out.println("Exception from DataBase.connectServer() : " +
- e.getMessage());
- }
- catch (ClassNotFoundException e) {
- System.out.println("Exception from DataBase.connectServer() : " +
- e.getMessage());
- }
- catch (IllegalAccessException e) {
- System.out.println("Exception from DataBase.connectServer() : " +
- e.getMessage());
- }
- isConnection = true;
- }
-
- void closeServer() {
- // disconnect with data base server.
- try {
- server.close();
- }
- catch (Exception e){
- System.out.println("Exception from DataBase.closeServer() : " +
- e.getMessage());
- }
- isConnection = false;
- }
-
- void setFirst(String rec) {
- try {
- Integer newFirst = new Integer(rec);
- firstRec = newFirst.intValue();
- }
- catch(NumberFormatException e) {
- System.out.println("Exception caught during setFirst() : " + e.getMessage());
- }
- }
-
- void setLast(String rec) {
- try {
- Integer newLast = new Integer(rec);
- lastRec = newLast.intValue();
- }
- catch(NumberFormatException e) {
- System.out.println("Exception caught during setLast() : " + e.getMessage());
- }
- }
-
- void search(String sqlStmt, boolean ascendingOrder) {
- // Execute sqlStmt which will most likely be a "Select * from customer ..." of some
- // sort assigning the resultSet. ResultSet will contain all records in the table.
- // also change the resultSet ordering flag to ascendingOrder
- search(sqlStmt);
- isAscending = ascendingOrder;
- }
-
- void search(String sqlStmt) {
- // Execute sqlStmt which will most likely be a "Select * from customer ..." of some
- // sort assigning the resultSet. ResultSet will contain all records in the table.
- try{
- Statement stmt = server.createStatement();
- resultSet = stmt.executeQuery(sqlStmt);
- resultSet.next();
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.search() : " +
- e.getMessage());
- }
- }
-
- void executeUpdate(String sqlStmt) {
- try {
- Statement stmt = server.createStatement();
- stmt.executeUpdate(sqlStmt);
- stmt.close();
- }
-
- catch(SQLException e) {
- System.out.println("Exception from DataBase.executeUpdate() : " +
- e.getMessage());
- }
- }
-
- boolean goNext(String id, boolean isPrevious) {
- // Scroll to the next record either forward or backward.
-
- // strictly for boundary checking
- Integer idValue = null;
- try {
- idValue = new Integer(id);
- }
- catch(NumberFormatException e) {
- System.out.println("Exception caught from goNext() : " + e.getMessage());
- }
-
- int idIntVal = idValue.intValue();
-
- if (( (idIntVal <= firstRec) && isPrevious ) ||
- ( (idIntVal >= lastRec) && !isPrevious) ) {
- return false;
- }
-
- // end of boundary checking...
-
- if((isAscending && !isPrevious) || (!isAscending && isPrevious) ){
- // if the resultSet is already in ascending order and we want to goNext or
- // if the resultSet is in descending order and we want to goPrevious,
- // simply do a next() on the resultSet.
- try {
- resultSet.next();
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.goNext() : " +
- e.getMessage());
- }
- }
- else {
- //if the resultSet is in descending order, produce a new resultSet
- //in ascending order and do a order change..
-
- //re-make the resultSet in ascending or descending order
- if(isAscending)
- search("SELECT * FROM customer ORDER by id DESC", false);
- else
- search("SELECT * FROM customer ORDER BY id ASC", true);
-
- Integer currentVal = Integer.valueOf(id);
-
- try {
-
- while(currentVal.intValue() != resultSet.getInt("id")){
- resultSet.next();
- }
-
- resultSet.next();
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.goNext() : " +
- e.getMessage());
- }
- }
- return true;
- }
-
- boolean goNext(String id) {
- // go to the next record w/ respect to customer id's in ascending order
- return goNext(id, false);
- }
-
- boolean goPrevious(String id) {
- // go to the previous record w/ respect to customer id's in ascending order
- return goNext(id, true);
- }
-
- void showTable(TextField[] textFieldList, int columnList[]) {
- // Show all records tied to textFields on our applet.
- textFieldList[0].setEditable(false);
- int n = textFieldList.length;
- for(int i = 0; i < n; i++) {
- try{
- textFieldList[i].setText(resultSet.getString(columnList[i]));
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.showTextFields() : " +
- e.getMessage());
- }
- }
- }
-
- String currentID()
- {
- // this is just a little helper method to extract the current customer id on
- // our current record.
-
- String returnStrg = new String("null");
-
- try {
- returnStrg = new String(resultSet.getString("id"));
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.currentID() : " +
- e.getMessage());
- }
- return returnStrg;
-
- }
-
- void clear(TextField[] textFieldList)
- {
- // clears all text in all the textFields.
- int n = textFieldList.length;
- String emptyString = new String();
-
- for(int i = 0; i < n; i++) {
- textFieldList[i].setText(emptyString);
- }
- }
-
- void goTo(String id)
- {
- //Goto the record indexed by id.
- Integer currentVal = Integer.valueOf(id);
-
- try {
- while(currentVal.intValue() != resultSet.getInt("id")){
- resultSet.next();
- }
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.goTo() : " +
- e.getMessage());
- }
- }
- }
- public class customer extends Applet {
-
- public void init() {
-
- // Connection Initializtion.
- dataBase = new
- DataBase("jdbc:dbaw://localhost:8889/Watcom/SQL Anywhere 5.0 Sample/SQL Anywhere", "dba", "sql");
-
- dataBase.connectServer("symantec.itools.db.jdbc.Driver");
-
- super.init();
-
- //{{INIT_CONTROLS
- setLayout(null);
- resize(553,423);
- titlePanel=new Panel();
- titlePanel.setFont(new Font("TimesRoman",Font.BOLD,10));
- titlePanel.setLayout(null);
- add(titlePanel);
- titlePanel.reshape(0,0,553,68);
- Title=new Label("Customer Information Sheet");
- Title.setFont(new Font("TimesRoman",Font.BOLD,36));
- titlePanel.add(Title);
- Title.reshape(49,15,455,45);
- custIDLabel=new Label("Cust. ID:");
- custIDLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(custIDLabel);
- custIDLabel.reshape(49,105,70,15);
- custIDTextField=new TextField(6);
- custIDTextField.setFont(new Font("Dialog",Font.BOLD,12));
- add(custIDTextField);
- custIDTextField.reshape(126,105,56,23);
- fnameTextField=new TextField(12);
- add(fnameTextField);
- fnameTextField.reshape(126,135,105,23);
- lnameTextField=new TextField(15);
- add(lnameTextField);
- lnameTextField.reshape(392,135,126,23);
- fnameLabel=new Label("First Name:");
- fnameLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(fnameLabel);
- fnameLabel.reshape(42,135,84,23);
- lnameLabel=new Label("Last Name:");
- lnameLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(lnameLabel);
- lnameLabel.reshape(301,135,77,23);
- addressTextField=new TextField(47);
- add(addressTextField);
- addressTextField.reshape(126,180,392,23);
- addressLabel=new Label("Address:");
- addressLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(addressLabel);
- addressLabel.reshape(56,180,63,23);
- cityLabel=new Label("City:");
- cityLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(cityLabel);
- cityLabel.reshape(77,218,42,22);
- cityTextField=new TextField(12);
- add(cityTextField);
- cityTextField.reshape(126,218,105,22);
- stateLabel=new Label("State:");
- stateLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(stateLabel);
- stateLabel.reshape(245,218,56,15);
- stateTextField=new TextField(4);
- add(stateTextField);
- stateTextField.reshape(301,218,35,22);
- zipLabel=new Label("ZIP:");
- add(zipLabel);
- zipLabel.reshape(371,218,42,22);
- zipTextField=new TextField(11);
- add(zipTextField);
- zipTextField.reshape(420,218,98,22);
- phoneLabel=new Label("Phone#:");
- phoneLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(phoneLabel);
- phoneLabel.reshape(56,263,63,15);
- phoneTextField=new TextField(12);
- add(phoneTextField);
- phoneTextField.reshape(126,263,105,22);
- comLabel=new Label("Company:");
- comLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(comLabel);
- comLabel.reshape(245,263,70,15);
- comTextField=new TextField(24);
- add(comTextField);
- comTextField.reshape(315,263,203,22);
- first=new Button("<<");
- first.setFont(new Font("Dialog",Font.BOLD,12));
- add(first);
- first.reshape(77,308,35,30);
- previous=new Button("<");
- previous.setFont(new Font("Dialog",Font.BOLD,12));
- add(previous);
- previous.reshape(119,308,35,30);
- next=new Button(">");
- next.setFont(new Font("Dialog",Font.BOLD,12));
- add(next);
- next.reshape(161,308,35,30);
- last=new Button(">>");
- last.setFont(new Font("Dialog",Font.BOLD,12));
- add(last);
- last.reshape(203,308,35,30);
- New=new Button("new");
- New.setFont(new Font("Dialog",Font.BOLD,12));
- add(New);
- New.reshape(273,308,49,30);
- add=new Button("add");
- add.setFont(new Font("Dialog",Font.BOLD,12));
- add(add);
- add.reshape(329,308,49,30);
- Update=new Button("update");
- Update.setFont(new Font("Dialog",Font.BOLD,12));
- add(Update);
- Update.reshape(385,308,49,30);
- searchChoiceBox= new Choice();
- refresh=new Button("refresh");
- refresh.setFont(new Font("Dialog",Font.BOLD,12));
- add(refresh);
- refresh.reshape(441,308,49,30);
- add(searchChoiceBox);
- searchChoiceBox.reshape(126,353,119,75);
- searchChoiceBox.addItem("id");
- searchChoiceBox.addItem("fname");
- searchChoiceBox.addItem("lname");
- searchChoiceBox.addItem("company_name");
- searchChoiceBox.addItem("zip");
- searchChoiceBox.addItem("state");
- searchChoiceBox.addItem("phone");
- searchLabel=new Label("Search By:");
- searchLabel.setFont(new Font("Dialog",Font.BOLD,12));
- add(searchLabel);
- searchLabel.reshape(35,353,84,15);
- searchTextField=new TextField(16);
- add(searchTextField);
- searchTextField.reshape(252,353,140,22);
- search=new Button("search");
- search.setFont(new Font("Dialog",Font.BOLD,12));
- add(search);
- search.reshape(399,353,49,22);
- close=new Button("close");
- close.setFont(new Font("Dialog",Font.BOLD,12));
- add(close);
- close.reshape(462,353,49,22);
- infoTextField=new TextField(53);
- add(infoTextField);
- infoTextField.reshape(77,383,441,22);
- //}}
-
- setBackground(Color.lightGray);
- infoTextField.setEditable(false);
-
- // extract first and last record id's for boundary checking
- dataBase.search("SELECT id FROM customer ORDER by id DESC", false);
- try { dataBase.setLast(dataBase.resultSet.getString("id"));}
- catch(SQLException e) { System.out.println(e.getMessage()); }
-
- // start off by generating all records in the customer table
- dataBase.search("SELECT * FROM customer ORDER BY id ASC", true);
-
- try { dataBase.setFirst(dataBase.resultSet.getString("id")); }
- catch(SQLException e) {System.out.println(e.getMessage()); }
-
- // one way to have global (w/ respect to only this class) variables
- // with initializers.
- TextField textFieldListLocal[] = {custIDTextField, fnameTextField, lnameTextField,
- addressTextField, cityTextField, stateTextField,
- zipTextField, phoneTextField, comTextField};
- textFieldList = textFieldListLocal;
-
- int columnListLocal[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- columnList = columnListLocal;
-
- // we want the id textField to be uneditable.
- custIDTextField.setEditable(false);
-
- //disable add button until there is a need to use it.
- add.disable();
-
- //Show the first record in our table.
- dataBase.showTable(textFieldList, columnList);
-
- }
-
- public boolean handleEvent(Event event) {
- if((event.target == next) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Processing Data Base on next request...");
- if(dataBase.goNext(dataBase.currentID())) {
- dataBase.showTable(textFieldList, columnList);
- ShowStatus("");
- }
- else
- ShowStatus("You've reached a dead end!");
-
- }
-
- else if((event.target == previous) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Processing Data Base on previous request...");
- if(dataBase.goPrevious(dataBase.currentID())) {
- dataBase.showTable(textFieldList, columnList);
- ShowStatus("");
- }
- else
- ShowStatus("You've reached a dead end!");
- }
-
- else if((event.target == first) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Processing Data Base on first request...");
- // generate a new resultSet in ascending order and show the first record
- // of this resultSet
- dataBase.search("SELECT * FROM customer ORDER BY id ASC", true);
- dataBase.showTable(textFieldList, columnList);
- ShowStatus("");
- }
-
- else if((event.target == last) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Processing Data Base on last request...");
- // generate a new resultSet in descending order and show the first record
- // of this resultSet
- dataBase.search("SELECT * FROM customer ORDER BY id DESC", false);
- dataBase.showTable(textFieldList, columnList);
- ShowStatus("");
- }
-
- else if((event.target == New) && (event.id == Event.ACTION_EVENT)) {
- custIDTextField.setEditable(true);
- add.enable();
- dataBase.clear(textFieldList);
- ShowStatus("");
- }
-
- else if((event.target == close) && (event.id == Event.ACTION_EVENT)) {
- dataBase.closeServer();
- }
-
- else if((event.target == add) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Attempting to add new record to Data Base...");
- String comma = new String(" , ");
- String quote = new String("'");
-
- // Some error checking: Illegal user input.
- // if something is illegal, clear the textfield and return.
- if(! errorHandling(textFieldList)) {
- return true;
- }
-
- // Does the customer id already exist.
- try {
- Statement stmt = dataBase.server.createStatement();
- ResultSet rs = stmt.executeQuery("select id from customer where id = " +
- custIDTextField.getText());
- rs.next();
- if(! rs.wasNull()) {
- ShowStatus("Cust. ID already exits, try another.");
- custIDTextField.setText("");
- return true;
- }
- stmt.close();
- }
- catch(SQLException e) {
- System.out.println("Exception caught during add : " + e.getMessage());
- }
-
-
-
-
- dataBase.search("select id from customer where id = " + custIDTextField.getText());
- try {
- if(! dataBase.resultSet.wasNull()) {
- ShowStatus("Customer ID already exits, try another.");
- custIDTextField.setText("");
- return true;
- }
- }
- catch(SQLException e) {
- System.out.println("Exception caught during add : " + e.getMessage());
- }
-
- String sqlStmt = new String ("insert into customer " + "( " + "id" + comma +
- "fname" + comma + "lname" + comma +
- "address" + comma + "city" + comma + "state" + comma+
- "zip" + comma + "phone" + comma +
- "company_name" + " ) " +
- "values" + " ( " + custIDTextField.getText() + comma
- + quote + fnameTextField.getText() + quote +
- comma + quote + lnameTextField.getText() + quote +
- comma + quote + addressTextField.getText() + quote +
- comma + quote + cityTextField.getText() + quote +comma
- + quote + stateTextField.getText() + quote + comma +
- quote + zipTextField.getText() + quote + comma + quote +
- phoneTextField.getText() + quote + comma + quote +
- comTextField.getText() + quote + " ) " );
-
- dataBase.executeUpdate(sqlStmt);
- add.disable();
- // check for possibility of a new firstRec or lastRec
- String id = new String(custIDTextField.getText());
- Integer idInteger = null;
- try {
- idInteger = new Integer(id);
- }
- catch(NumberFormatException e) {
- System.out.println("Exception caught in add() : " + e.getMessage());
- }
-
- if(idInteger.intValue() < dataBase.firstRec)
- dataBase.setFirst(id);
- if(idInteger.intValue() > dataBase.lastRec)
- dataBase.setLast(id);
-
- custIDTextField.setEditable(false);
- dataBase.search("SELECT * FROM customer WHERE id >= " +
- custIDTextField.getText() + " ORDER by id ASC", true);
- ShowStatus("");
- }
-
- else if((event.target == Update) && (event.id == Event.ACTION_EVENT)) {
- ShowStatus("Attempting to update record #" + dataBase.currentID() +
- " from Data Base ...");
- String quote = new String("'");
- String comma = new String(" , ");
- String sqlStmt = new String("UPDATE customer SET fname = " +
- quote + fnameTextField.getText() +
- quote + comma + "lname = " + quote +
- lnameTextField.getText() + quote + comma +
- "address = " + quote +
- addressTextField.getText() + quote +
- comma + "state = " + quote + stateTextField.getText() +
- quote + comma + "city = " + quote + cityTextField.getText()
- + quote + comma + "zip = " + quote +
- zipTextField.getText() + quote + comma +
- "phone = " + quote + phoneTextField.getText() + quote
- + comma + "company_name = " + quote +
- comTextField.getText() + quote +
- " WHERE id = " + dataBase.currentID());
-
- dataBase.executeUpdate(sqlStmt);
- add.disable();
- dataBase.search("SELECT * FROM customer WHERE id >= " +
- Integer.valueOf(custIDTextField.getText())
- + " ORDER by id ASC", true);
- ShowStatus("");
-
- }
-
- else if((event.target == refresh) && (event.id == Event.ACTION_EVENT)) {
- // refresh dataBase, especially afer searches
- ShowStatus("Refreshing Data Base...");
- String sqlStmt = new String("select * from customer order by id asc");
- dataBase.search(sqlStmt, true);
- dataBase.showTable(textFieldList, columnList);
- ShowStatus("");
- }
-
- else if((event.target == search) && (event.id == Event.ACTION_EVENT)) {
- String key = searchTextField.getText();
- String sqlStmt = null;
- String countSql = null;
- String searchItem = searchChoiceBox.getSelectedItem();
-
- ShowStatus("Searching for key: " + key + " from Data Base...");
- if(key.equals("")) {
- //if the textfield contains nothing, do nothing.
- return true;
- }
- else if(! searchItem.equals("id")) {
- // if search by other than Customer ID
- String quote = new String("'");
- countSql = "SELECT COUNT (id) FROM customer WHERE "
- + searchItem + " = " +
- quote + key + quote;
- sqlStmt = new String("SELECT * FROM customer WHERE " +
- searchItem + " = " +
- quote + key + quote + "ORDER BY id ASC");
-
- }
- else { // must be performing a search with respect to customer ID.
- // Some error checking: Illegal user input.
- if (!isNumeric(key)) {
- ShowStatus("customer ID must be a number!!");
- searchTextField.setText("");
- return true;
- }
- countSql = "SELECT COUNT (id) FROM customer WHERE id = "
- + key;
- sqlStmt = new String("SELECT * FROM customer WHERE id >= "
- + key + " ORDER BY id ASC");
- }
- String currentID = new String(dataBase.currentID());
- int countRecs = 0;
- try {
- Statement stmt = dataBase.server.createStatement();
- ResultSet rs = stmt.executeQuery(countSql);
- rs.next();
- countRecs = rs.getInt(1);
- stmt.close();
- }
- catch(SQLException e) {
- System.out.println("Exception caught in search : " + e.getMessage());
- }
-
- if(countRecs == 0) {
- ShowStatus("No records retrieved from key: " + key);
- return true;
- }
- ShowStatus(countRecs + " record(s) retrieved from key : " + key);
- dataBase.search(sqlStmt, true);
- dataBase.showTable(textFieldList, columnList);
-
- }
- else if (event.id == Event.WINDOW_DESTROY) {
- dataBase.closeServer();
- System.exit(0);
- }
- showDefaultStatus();
- return super.handleEvent(event);
- }
-
-
- // method to check if a string is numeric.
- boolean isNumeric(String number) {
-
- try {
- Integer val = new Integer(number);
- return true;
- }
- catch(NumberFormatException e) {
- System.out.println("Exception from isNumeric() : " + e.getMessage());
- return false;
- }
- }
-
- boolean errorHandling(TextField[] textFieldList) {
-
- if (!isNumeric(custIDTextField.getText())) {
- ShowStatus("customer ID must be a number!!");
- custIDTextField.setText("");
- return false;
- }
- return true;
- }
-
- void ShowStatus(String s) {
- infoTextField.setText(s);
- }
-
- void showDefaultStatus() {
- getAppletContext().showStatus("Symantec Corp., 1996");
- }
-
- //Tabbing stuff... from Ankur
-
- public void start() {
- custIDTextField.requestFocus();
- }
-
- public boolean keyDown(Event evt, int key) {
- if ((key==9) || (key==10)) {
- tab(evt);
- return true;
- }
- else return super.keyDown(evt, key);
- }
-
- void tab(Event evt) {
- Component temp = (Component)evt.target;
- boolean shiftpressed=evt.shiftDown();
-
- int index = tabindex(temp, shiftpressed);
- Component newtab = temp.getParent().getComponent(index);
- newtab.requestFocus();
- if (newtab instanceof TextField)
- ((TextField)newtab).selectAll();
- }
-
- int tabindex(Component current, boolean shiftpressed) { //Returns the tab index of the next component
- Component[] temp;
- temp = current.getParent().getComponents();
- int increment;
- boolean foundit=false;
-
- if (!(shiftpressed))
- {
- increment=1;
- for (int i=0;i<(temp.length)-1;i++)
- {
- if (current == temp[i]) foundit=true;
- if (foundit)
- {
- Component next=temp[i+increment];
- if ((next instanceof TextComponent) || (next instanceof Choice) || (next instanceof Button) || (next instanceof List))
- return (i+increment);
- else if (next instanceof Checkbox)
- {
- Checkbox tempcheckbox=(Checkbox)next;
- if (tempcheckbox.getCheckboxGroup()==null) return (i+increment);
- }
- }
- }
- }
- else
- {
- increment=-1;
- for (int i=(temp.length)-1;i>=1;i--) {
- if (current == temp[i]) foundit=true;
- if (foundit)
- {
- Component next=temp[i+increment];
- if ((next instanceof TextComponent) || (next instanceof Choice) || (next instanceof Button) || (next instanceof List))
- return (i+increment);
- else if (next instanceof Checkbox)
- {
- Checkbox tempcheckbox=(Checkbox)next;
- if (tempcheckbox.getCheckboxGroup()==null) return (i+increment);
- }
- }
- }
- }
- if (shiftpressed) {return (temp.length)-1;} else return 0; //Base case or if we've hit the final component
- }
- // end of tabbing stuff.
-
-
- //{{DECLARE_CONTROLS
- Panel titlePanel;
- Label Title;
- TextField fnameTextField;
- TextField lnameTextField;
- Label fnameLabel;
- Label lnameLabel;
- TextField addressTextField;
- Label addressLabel;
- Label cityLabel;
- TextField cityTextField;
- Label stateLabel;
- TextField stateTextField;
- Label zipLabel;
- TextField zipTextField;
- Label phoneLabel;
- TextField phoneTextField;
- Label comLabel;
- TextField comTextField;
- Button first;
- Button previous;
- Button next;
- Button last;
- Button New;
- Button add;
- Button Update;
- Choice searchChoiceBox;
- Label searchLabel;
- TextField searchTextField;
- Button close;
- Label custIDLabel;
- TextField custIDTextField;
- Button search;
- Button refresh;
- TextField infoTextField;
- //}}
-
- DataBase dataBase;
- TextField textFieldList[];
- int columnList[];
-
- }
-