home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 9.2 KB | 217 lines |
- /**************************************************************************************************
- * *
- * Class name: categoryEntry *
- * *
- * Purpose: Extends Panel to allow user to add new categories for Expenses. *
- * *
- * Imports: java.awt.* *
- * java.applet.* *
- * symjava.sql.* *
- * java.net.*; *
- * java.lang.*; *
- * java.util.*; *
- * *
- * Methods include: public boolean handleEvent(Event event) *
- * public categoryEntry(Applet parent) *
- * public class categoryEntry extends Panel *
- * public String checkFields() *
- * public synchronized void show() *
- * public void clickedclearbutton() *
- * public void clickedMainMenubutton() *
- * public void clickedSavebutton() *
- * public void getMessageBox(String msg) *
- * *
- * *
- * 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.applet.*;
- import java.net.*;
- import java.awt.*;
- import symjava.sql.*;
- import java.lang.*;
- import java.util.*;
-
- public class categoryEntry extends Panel {
-
- expenseApplet exp;
-
- public categoryEntry(Applet parent) {
-
-
- exp = (expenseApplet)parent;
-
- //{{INIT_CONTROLS
- setLayout(null);
- insets().left -= 60;
- resize(insets().left + insets().right + 770, insets().top + insets().bottom + 390);
-
- label1=new Label("Category ID");
- add(label1);
- label1.reshape(insets().left + 25,insets().top + 47,85,15);
-
- categoryID=new TextField(14);
- add(categoryID);
- categoryID.reshape(insets().left + 165,insets().top + 39,189,25);
-
- label2=new Label("Category Name");
- add(label2);
- label2.reshape(insets().left + 25,insets().top + 126,103,15);
-
- categoryName=new TextField(22);
- add(categoryName);
- categoryName.reshape(insets().left + 165,insets().top + 120,189,26);
-
- label3=new Label("Category Account #");
- add(label3);
- label3.reshape(insets().left + 25,insets().top + 86,119,15);
-
- categoryAccount=new TextField(14);
- add(categoryAccount);
- categoryAccount.reshape(insets().left + 165,insets().top + 79,189,26);
-
- savebutton=new Button("Save");
- add(savebutton);
- savebutton.reshape(insets().left + 50,insets().top + 185,88,26);
-
- clearbutton=new Button("Clear");
- add(clearbutton);
- clearbutton.reshape(insets().left + 150,insets().top + 185,88,26);
-
- MainMenubutton=new Button("Main Menu");
- add(MainMenubutton);
- MainMenubutton.reshape(insets().left + 250,insets().top + 185,88,26);
- //}}
-
-
- categoryID.setEditable(false);
- }
-
- public synchronized void show() {
- super.show();
-
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.ACTION_EVENT && event.target == savebutton) {
- clickedSavebutton();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == clearbutton) {
- clickedclearbutton();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == MainMenubutton) {
- clickedMainMenubutton();
- return true;
- }
-
- return super.handleEvent(event);
- }
-
-
- //{{DECLARE_CONTROLS
- Label label1;
- TextField categoryID;
- Label label2;
- TextField categoryName;
- Label label3;
- TextField categoryAccount;
- Label label5;
- Button savebutton;
- Button clearbutton;
- Button MainMenubutton;
- //}}
-
-
-
- /*
- public void getMessageBox(String msg) {
- MessageBox theMessageBox;
- theMessageBox = new MessageBox(this, msg);
- theMessageBox.show();
- }
- */
- public void clickedMainMenubutton() {
- hide();
- }
- public void clickedSavebutton() {
- Statement s, s1;
- ResultSet rs2;
-
- String errMessage = "";
- errMessage = checkFields();
-
- if (errMessage.equals("")) {
-
- String catName = categoryName.getText();
- //int catAccount = (Integer.valueOf(categoryAccount.getText())).intValue();
- String catAccount = categoryAccount.getText();
- int rs =0;
- //String sqlStatement = "Insert into Expense_Categories (ExpenseCategory, ExpenseCategoryAccount) values ('" + catName + "'," + catAccount + ")";
- String sqlStatement = "insert into Expense_Categories (ExpenseCategory, ExpenseAccountNumber, ExpenseCategoryID) values ('" + catName + "','" + catAccount + "','" + catAccount + "')";
-
- /********************** Query the Expense Categories Table ****************************************/
- try
- {
- s = (Statement)exp.connection.createStatement();
- rs = s.executeUpdate(sqlStatement);
- s1 = (Statement)exp.connection.createStatement();
- sqlStatement = "Select ExpenseCategoryID from Expense_Categories where ExpenseCategory = '" + catName + "'";
- rs2 = (ResultSet)s1.executeQuery(sqlStatement);
-
- categoryID.setText(rs2.getString(1));
-
- s.close();
- }
- catch (SQLException e)
- {
- String errmsg = (e.getMessage());
- System.out.println(errmsg);
- return;
- }
- /**************************************************************************************************/
- }
- else {
- // getMessageBox(errMessage);
- }
- }
-
- //**** clear all entry fields ****
- public void clickedclearbutton() {
- categoryName.setText(null);
- categoryID.setText(null);
- categoryAccount.setText(null);
- }
-
- //**** check that all fields are entered ****
- public String checkFields() {
- String errMessage = "";
-
- if (categoryName.getText().equals(""))
- errMessage = "Please enter Category Name ";
- if (categoryAccount.getText().equals(""))
- errMessage = "Please enter Category Account ";
-
- return errMessage;
- }
-
- }
-
-