home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 31.8 KB | 863 lines |
- /*************************************************************************************************************************
- *
- *
- * Class name: inventory()
- * Purpose: This class was created to encapsulate data and provide services such as:
- * nextRecord() previousRecord() and search().
- *
- * Imports: java.awt.*
- * symjava.sql.*
- * java.applet.*
- * java.util.*
- *
- * Methods include: private boolean establishDBConnection()
- * public public class inventory
- * public boolean handleEvent(Event event)
- * public boolean keyDown(Event evt, int key)
- * void connectServer(String driver_name)
- * void search(String sqlStmt)
- *
- * 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 code.
- *
- * Copyright (c) 1996 Symantec. All Rights Reserved.
- *
- *************************************************************************************************************************/
-
- import java.awt.*;
- import java.applet.*;
- import symjava.sql.*;
- import java.util.*;
-
- 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 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 product ..." of some
- // sort assigning the resultSet. ResultSet will contain all records in the table.
- // also change the resultSet ordering to ascendingOrder
- search(sqlStmt);
- isAscending = ascendingOrder;
- }
-
- void search(String sqlStmt) {
- // Execute sqlStmt which will most likely be a "Select * from product ..." 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 orderChange().
-
- //re-make the resultSet in ascending or descending order
- if(isAscending)
- search("SELECT * FROM product ORDER by id DESC", false);
- else
- search("SELECT * FROM product 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 product id's in ascending order
- return goNext(id, false);
- }
-
- boolean goPrevious(String id) {
- // go to the previous record w/ respect to product id's in ascending order
- return goNext(id, true);
- }
-
- void showTable(TextField[] textFieldList, int textFieldColList[],
- Choice[] choiceList, int choiceColList[])
- // traverve the list of textFields and choices and show'em on our applet.
- // note: if we were to have check boxes on this applet we would have to
- // include that in our parameter list as well.
- {
- // make prodIDTextField uneditable before showing.
- textFieldList[0].setEditable(false);
- showTextFields(textFieldList, textFieldColList);
- showChoice(choiceList, choiceColList);
- }
-
-
- void showTextFields(TextField[] textFieldList, int columnList[]) {
- // Show all records tied to textFields on our applet.
-
- int n = textFieldList.length;
- for(int i = 0; i < n; i++) {
- try{
- //kludge when columnList[i] == unit_price column
- if(columnList[i] == 7)
- textFieldList[i].setText(
- (resultSet.getBigDecimal(columnList[i],2)).toString());
- else
- textFieldList[i].setText(resultSet.getString(columnList[i]));
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.showTextFields() : " +
- e.getMessage());
- }
- }
- }
-
-
- void showChoice(Choice[] choiceList, int colList[]) {
- // Show all records tied to choiceBoxes on our applet.
- int n = choiceList.length;
- for(int i = 0; i < n; i++) {
- try {
- choiceList[i].select(resultSet.getString(colList[i]));
- }
- catch(SQLException e) {
- System.out.println("Exception from DataBase.showChoice() : " +
- e.getMessage());
- }
- }
- }
-
- String currentID()
- {
- // this is just a little helper method to extract the current product 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 inventory extends Applet {
-
- public void init() {
-
- super.init();
-
-
- // Connection Initializtion.
- dataBase = new
- DataBase("jdbc:dbaw://localhost:8889/Watcom/SQL Anywhere 5.0 Sample/SQLAnywhere", "dba", "sql");
- dataBase.connectServer("symantec.itools.db.jdbc.Driver");
-
- setBackground(Color.lightGray);
-
- //{{INIT_CONTROLS
- setLayout(null);
- resize(546,404);
- titleLabel=new Label("Inventory Applet");
- titleLabel.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,22));
- add(titleLabel);
- titleLabel.reshape(168,0,168,30);
- prodIDTextField=new TextField(11);
- add(prodIDTextField);
- prodIDTextField.reshape(91,75,91,23);
- prodIDLabel=new Label("Prod. ID:");
- prodIDLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(prodIDLabel);
- prodIDLabel.reshape(0,75,77,23);
- nameLabel=new Label("Name:");
- nameLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(nameLabel);
- nameLabel.reshape(0,105,63,23);
- nameTextField=new TextField(12);
- add(nameTextField);
- nameTextField.reshape(91,105,105,23);
- descpLabel=new Label("Description:");
- descpLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(descpLabel);
- descpLabel.reshape(0,135,91,15);
- descpTextField=new TextField(44);
- add(descpTextField);
- descpTextField.reshape(91,135,371,23);
- sizeLabel=new Label("Size:");
- sizeLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(sizeLabel);
- sizeLabel.reshape(0,165,70,15);
- sizeTextField=new TextField(15);
- add(sizeTextField);
- sizeTextField.reshape(91,165,126,23);
- colorLabel=new Label("Color:");
- colorLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(colorLabel);
- colorLabel.reshape(0,195,70,15);
- colorChoiceBox= new Choice();
- add(colorChoiceBox);
- colorChoiceBox.reshape(91,195,112,98);
- colorChoiceBox.addItem("Black");
- colorChoiceBox.addItem("White");
- colorChoiceBox.addItem("Blue");
- colorChoiceBox.addItem("Red");
- colorChoiceBox.addItem("Yellow");
- colorChoiceBox.addItem("Violet");
- quanLabel=new Label("Quantity:");
- quanLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(quanLabel);
- quanLabel.reshape(0,225,70,23);
- quanTextField=new TextField(9);
- add(quanTextField);
- quanTextField.reshape(91,225,77,23);
- priceLabel=new Label("Unit Price:");
- priceLabel.setFont(new Font("TimesRoman",Font.BOLD,14));
- add(priceLabel);
- priceLabel.reshape(0,255,84,15);
- priceTextField=new TextField(11);
- add(priceTextField);
- priceTextField.reshape(91,255,98,23);
- searchLabel=new Label("Search By:");
- searchLabel.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,14));
- add(searchLabel);
- searchLabel.reshape(203,255,77,23);
- searchChoiceBox= new Choice();
- add(searchChoiceBox);
- searchChoiceBox.reshape(280,255,91,75);
- searchChoiceBox.addItem("Prod. ID#");
- searchChoiceBox.addItem("Name");
- searchTextField=new TextField(11);
- add(searchTextField);
- searchTextField.reshape(371,255,98,23);
- search=new Button("Search");
- add(search);
- search.reshape(476,255,56,23);
- first=new Button("<<");
- first.setFont(new Font("Dialog",Font.BOLD,12));
- add(first);
- first.reshape(161,285,35,30);
- previous=new Button("<");
- previous.setFont(new Font("Dialog",Font.BOLD,12));
- add(previous);
- previous.reshape(210,285,35,30);
-
- next=new Button(">");
- next.setFont(new Font("Dialog",Font.BOLD,12));
- add(next);
- next.reshape(259,285,35,30);
-
- last=new Button(">>");
- last.setFont(new Font("Dialog",Font.BOLD,12));
- add(last);
- last.reshape(308,285,35,30);
- New=new Button("New");
- New.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,14));
- add(New);
- New.reshape(133,322,49,30);
- add=new Button("Add");
- add.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,14));
- add(add);
- add.reshape(196,322,49,30);
-
- Update=new Button("Update");
- Update.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,14));
- add(Update);
- Update.reshape(259,322,49,30);
- close=new Button("Close");
- close.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,14));
- add(close);
- close.reshape(322,322,49,30);
- infoTextField=new TextField(39);
- add(infoTextField);
- infoTextField.reshape(91,367,322,23);
- //}}
-
- // one way to have global (w/ respect to only this class) variables
- // with initializers.
- TextField textFieldListLocal[] = {prodIDTextField, nameTextField, descpTextField,
- sizeTextField, quanTextField, priceTextField};
- textFieldList = textFieldListLocal;
-
- int columnListLocal[] = {1, 2, 3, 4, 6, 7};
- columnList = columnListLocal;
-
- Choice choiceListLocal[] = {colorChoiceBox};
- choiceList = choiceListLocal;
-
- int choiceColListLocal[] = {5};
- choiceColList = choiceColListLocal;
-
- // extract first and last record id's for boundary checking
- dataBase.search("SELECT id FROM product 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 product table
- dataBase.search("SELECT * FROM product ORDER BY id ASC", true);
-
- try { dataBase.setFirst(dataBase.resultSet.getString("id")); }
- catch(SQLException e) {System.out.println(e.getMessage()); }
-
- // we want the id textField to be uneditable.
- prodIDTextField.setEditable(false);
-
- //disable add button until there is a need to use it.
- add.disable();
- infoTextField.setEditable(false);
-
- //Show the first record in our table.
- dataBase.showTable(textFieldList, columnList, choiceList, choiceColList);
-
- }
-
- 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, choiceList, choiceColList);
- 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, choiceList, choiceColList);
- 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 product ORDER BY id ASC", true);
- dataBase.showTable(textFieldList, columnList, choiceList, choiceColList);
- 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 product ORDER BY id DESC", false);
- dataBase.showTable(textFieldList, columnList, choiceList, choiceColList);
- ShowStatus("");
- }
-
- else if((event.target == New) && (event.id == Event.ACTION_EVENT)) {
- prodIDTextField.setEditable(true);
- add.enable();
- dataBase.clear(textFieldList);
- }
-
- else if((event.target == close) && (event.id == Event.ACTION_EVENT)) {
- dataBase.closeServer();
- }
-
- else if((event.target == add) && (event.id == Event.ACTION_EVENT)) {
- String status = new String("Attempting to add record: " +
- prodIDTextField.getText() + " into Data Base.");
- ShowStatus(status);
- String comma = new String(",");
- String quote = new String("'");
-
- // Some error checking: Illegal user input.
- if (!isInteger(prodIDTextField.getText())) {
- ShowStatus("product ID must be a number!!");
- prodIDTextField.setText("");
- return true;
- }
- if(!isInteger(quanTextField.getText())) {
- ShowStatus("quantity must be a number!");
- quanTextField.setText("");
- return true;
- }
-
-
- // Does the product id already exist?
- try {
- Statement stmt = dataBase.server.createStatement();
- ResultSet rs = stmt.executeQuery("select id from product where id = " +
- prodIDTextField.getText());
- rs.next();
- if(! rs.wasNull()) {
- ShowStatus("Prod. ID already exits, try another.");
- prodIDTextField.setText("");
- return true;
- }
- stmt.close();
- }
- catch(SQLException e) {
- System.out.println("Exception caught during add : " + e.getMessage());
- }
-
- String sqlStmt = new String ("INSERT INTO product" + " (" + "id" + comma +
- "name " + comma + " description " + comma +
- " size " + comma + " color " + comma +
- " quantity " + comma + " unit_price " + ") " +
- " VALUES " + "( " + prodIDTextField.getText() + comma
- + quote + nameTextField.getText() + quote +
- comma + quote + descpTextField.getText() + quote +
- comma + quote + sizeTextField.getText() + quote +
- comma + quote +
- colorChoiceBox.getSelectedItem() + quote + comma +
- quanTextField.getText() + comma +
- priceTextField.getText() + ")" );
- dataBase.executeUpdate(sqlStmt);
- add.disable();
- // check for possibility of a new firstRec or lastRec
- String id = new String(prodIDTextField.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);
-
- prodIDTextField.setEditable(false);
- dataBase.search("SELECT * FROM product WHERE id >= " +
- prodIDTextField.getText() + " ORDER by id ASC", true);
-
- ShowStatus("");
- }
-
- else if((event.target == Update) && (event.id == Event.ACTION_EVENT)) {
- String status = new String("Attempting to update record: " +
- prodIDTextField.getText() + " into Data Base.");
- ShowStatus(status);
- String quote = new String("'");
- // Some error checking: Illegal User input.
- if(!isInteger(quanTextField.getText())) {
- ShowStatus("quantity must be a number!");
- quanTextField.setText("");
- return true;
- }
-
- String sqlStmt = new String("UPDATE product SET name = " +
- quote + nameTextField.getText() +
- quote + " , " + "description = " + quote +
- descpTextField.getText() + quote + " , " +
- "size = " + quote +
- sizeTextField.getText() + quote +
- " , " + "quantity = " +
- quanTextField.getText() + " , " + "color = " + quote +
- colorChoiceBox.getSelectedItem() + quote + " , " +
- "unit_price = " + priceTextField.getText() +
- " WHERE id = " + dataBase.currentID());
-
- dataBase.executeUpdate(sqlStmt);
- add.disable();
- dataBase.search("SELECT * FROM product WHERE id >= " +
- Integer.valueOf(prodIDTextField.getText())
- + " ORDER by id ASC", true);
- ShowStatus("");
-
- }
- else if((event.target == search) && (event.id == Event.ACTION_EVENT)) {
- String status = new String("Searching for key: " + searchTextField.getText() +
- " in Data Base.");
- ShowStatus(status);
- String key = searchTextField.getText();
- String countSql = null;
- String sqlStmt = null;
-
- if(key.equals("")) {
- //if the textfield contains nothing, do nothing.
- return true;
- }
- else if((searchChoiceBox.getSelectedItem()).equals("Name")) {
- // if search by "Name"
- String subSqlStmt;
- String prodID;
- String quote = new String("'");
- countSql = "SELECT COUNT (id) FROM product WHERE name = " +
- quote + key + quote;
- subSqlStmt = new String("SELECT * FROM product WHERE name = " +
- quote + key + quote + " ORDER BY id ASC");
- dataBase.search(subSqlStmt);
-
- try {
- prodID = new String(dataBase.resultSet.getString("id"));
- sqlStmt = new String("SELECT * FROM product WHERE id >=" +
- prodID + " ORDER BY id ASC");
- }
- catch(SQLException e) {
- System.out.println("Exception caught when search button was struck : "
- + e.getMessage());
- }
- }
- else { // must be performing a search with respect to prod ID.
-
- // Some error checking: Illegal user input.
- if (!isInteger(searchTextField.getText())) {
- ShowStatus("product ID must be a number!!");
- searchTextField.setText("");
- return true;
- }
-
- countSql = "SELECT COUNT (id) FROM product WHERE id = "
- + key;
- sqlStmt = new String("SELECT * FROM product WHERE id >= "
- + key + " ORDER BY id ASC");
- }
-
- 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, choiceList, choiceColList);
- }
- else if (event.id == Event.WINDOW_DESTROY) {
- dataBase.closeServer();
- System.exit(0);
- }
- showDefaultStatus();
- return super.handleEvent(event);
-
- }
-
- //Tabbing
-
- public void start() {
- prodIDTextField.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
-
- // method to check if a string is numeric.
- boolean isInteger(String number) {
-
- try {
- Integer val = new Integer(number);
- return true;
- }
- catch(NumberFormatException e) {
- System.out.println("Exception from isInteger() : " + e.getMessage());
- return false;
- }
- }
-
- void ShowStatus(String s) {
- infoTextField.setText(s);
- }
-
- void showDefaultStatus() {
- showStatus("Symantec Corp., 1996");
- }
-
- //{{DECLARE_CONTROLS
- Label titleLabel;
- TextField prodIDTextField;
- Label prodIDLabel;
- Label nameLabel;
- TextField nameTextField;
- Label descpLabel;
- TextField descpTextField;
- Label sizeLabel;
- TextField sizeTextField;
- Label colorLabel;
- Choice colorChoiceBox;
- Label quanLabel;
- TextField quanTextField;
- Label priceLabel;
- TextField priceTextField;
- Label searchLabel;
- Choice searchChoiceBox;
- TextField searchTextField;
- Button next;
- Button previous;
- Button first;
- Button last;
- Button New;
- Button close;
- Button add;
- Button search;
- Button Update;
- TextField infoTextField;
- //}}
-
-
- DataBase dataBase;
- TextField textFieldList[];
- int columnList[];
- Choice choiceList[];
- int choiceColList[];
- }
-