Hello, I was hoping that someone might be able to help me with this program:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;

public class CustomerInfo extends JFrame implements ActionListener
{
	//construct components
	JTextPane textPane = new JTextPane();

	//initialize data in arrays
	public void readFile()
	{
		BufferedReader br = null;
		String[] custID = new String[100];
		String[] firstName = new String[100];
		String[] lastName = new String[100];
		String[] addressOne = new String[100];
		String[] addressTwo = new String[100];
		String[] myCity = new String[100];
		String[] myState = new String[100];
		String[] myCountry = new String[100];
		String[] productionID = new String[100];
		int num = 0;

		try
		{
			br = new BufferedReader(new FileReader("Database.txt"));
			String line = null;

			while ((line = br.readLine()) != null)
			{
				String[] values = line.split(",");
				if (values.length > 1)
				{
					custID[num] = values[0];
					firstName[num] = values[1];
					lastName[num] = values[2];
					addressOne[num] = values[3];
					addressTwo[num] = values[4];
					myCity[num] = values[5];
					myState[num] = values[6];
					myCountry[num] = values[7];
					productionID[num] = values[8];
					num++;
				}
			}
		}
		catch (FileNotFoundException ex)
		{
			ex.printStackTrace();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if (br != null)
				br.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}

	//construct instance of CustomerInfo
	public CustomerInfo()
	{
		super("Customer Information Database");
	}

	//create the menu system
	public JMenuBar createMenuBar()
	{
		//create an instance of the menu
		JMenuBar mnuBar = new JMenuBar();
		setJMenuBar(mnuBar);

		//construct and populate the File menu
		JMenu mnuFile = new JMenu("File", true);
			mnuFile.setMnemonic(KeyEvent.VK_F);
			mnuFile.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuFile);

		JMenuItem mnuFileExit = new JMenuItem("Exit");
			mnuFileExit.setMnemonic(KeyEvent.VK_X);
			mnuFileExit.setDisplayedMnemonicIndex(1);
			mnuFile.add(mnuFileExit);
			mnuFileExit.setActionCommand("Exit");
			mnuFileExit.addActionListener(this);

		//construct and populate the Edit menu
		JMenu mnuEdit = new JMenu("Edit", true);
			mnuEdit.setMnemonic(KeyEvent.VK_E);
			mnuEdit.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuEdit);

		JMenu mnuEditSearch = new JMenu("Search");
			mnuEditSearch.setMnemonic(KeyEvent.VK_R);
			mnuEditSearch.setDisplayedMnemonicIndex(3);
			mnuEdit.add(mnuEditSearch);

		JMenuItem mnuEditSearchByName = new JMenuItem("by Last Name");
			mnuEditSearchByName.setMnemonic(KeyEvent.VK_L);
			mnuEditSearchByName.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByName);
			mnuEditSearchByName.setActionCommand("last");
			mnuEditSearchByName.addActionListener(this);

		JMenuItem mnuEditSearchByProdNum = new JMenuItem("by Product Number");
			mnuEditSearchByProdNum.setMnemonic(KeyEvent.VK_P);
			mnuEditSearchByProdNum.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByProdNum);
			mnuEditSearchByProdNum.setActionCommand("production");
			mnuEditSearchByProdNum.addActionListener(this);

		JMenuItem mnuEditSearchByState = new JMenuItem("by State");
			mnuEditSearchByState.setMnemonic(KeyEvent.VK_S);
			mnuEditSearchByState.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByState);
			mnuEditSearchByState.setActionCommand("state");
			mnuEditSearchByState.addActionListener(this);

		return mnuBar;
	}

	//create the content pane
	public Container createContentPane()
	{

		//construct and populate the north panel
		JPanel northPanel = new JPanel();
			northPanel.setLayout(new FlowLayout());

		//create the JTextPane and center panel
		JPanel centerPanel = new JPanel();
			setTabsAndStyles(textPane);
			textPane = addTextToTextPane();
			JScrollPane scrollPane = new JScrollPane(textPane);
				scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
				scrollPane.setPreferredSize(new Dimension(500, 200));
			centerPanel.add(scrollPane);

		//create Container and set attributes
		Container c = getContentPane();
			c.setLayout(new BorderLayout(10,10));
			c.add(northPanel,BorderLayout.NORTH);
			c.add(centerPanel,BorderLayout.CENTER);

		return c;
	}

	//method to create tab stops and set font styles
	protected void setTabsAndStyles(JTextPane textPane)
	{
		//create Tab Stops
		TabStop[] tabs = new TabStop[2];
			tabs[0] = new TabStop(200, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[1] = new TabStop(350, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
		TabSet tabset = new TabSet(tabs);

		//set Tab Style
		StyleContext tabStyle = StyleContext.getDefaultStyleContext();
		AttributeSet aset = tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
		textPane.setParagraphAttributes(aset, false);

		//set Font Style
		Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

		Style regular = textPane.addStyle("regular", fontStyle);
		StyleConstants.setFontFamily(fontStyle, "SansSerif");

		Style s = textPane.addStyle("italic", regular);
		StyleConstants.setItalic(s, true);

		s = textPane.addStyle("bold", regular);
		StyleConstants.setBold(s, true);

		s = textPane.addStyle("large", regular);
		StyleConstants.setFontSize(s, 16);
	}

	//method to add new text to the JTextPane
	public JTextPane addTextToTextPane()
	{
		Document doc = textPane.getDocument();
		try
		{
			//clear previous text
			doc.remove(0, doc.getLength());

			//insert title
			doc.insertString(0,"CUST ID\tLAST NAME\tFIRST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//insert detail
			for (int j = 0; j < lastName.length; j++)
			{
				doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
				doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}

		return textPane;
	}

	//event to process user clicks
	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();

		//user clicks Exit on the File menu
		if (arg == "Exit")
			System.exit(0);

		//user clicks title on the Search submenu
		if (arg == "last")
			search(arg, last);

		//user clicks studio on the Search submenu
		if (arg == "production")
			search(arg, production);

		//user clicks state on the Search submenu
		if (arg == "state")
			search(arg, state);
	}

	//method to search arrays
	public void search(String searchField, String searchArray[])
	{
		try
		{
			Document doc = textPane.getDocument();	//assign text to document object
			doc.remove(0,doc.getLength());	//clear previous text

			//display column titles
			doc.insertString(0,"CUST ID\tLAST NAME\tFIRST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//prompt user for search data
			String search = JOptionPane.showInputDialog(null, "Please enter the "+ searchField);
			boolean found = false;

			//search arrays
			for (int i = 0; i < lastName.length; i++)
			{
				if (search.compareTo(searchArray[i])==0)
				{
					doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
					doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
					found = true;
				}
			}
			if (found == false)
			{
				JOptionPane.showMessageDialog(null, "Your search produced no results.", "No results found",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}
	}

	//main method executes at run time
	public static void main(String args[])
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		CustomerInfo f = new CustomerInfo();
		f.readFile();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setJMenuBar(f.createMenuBar());
		f.setContentPane(f.createContentPane());
		f.setSize(600,375);
		f.setVisible(true);
	}
}

I am getting an error starting at line 205 with the variable "lastName". I am getting the 'cannont resovle symbol' error with this variable amd the other array variable I had set up to read the columns of a text file. I am thinking that since the technique of reading the text file is embedded in its own prodecure that maybe the variables are not recongized by other procedures.

I would appreciate any help that anyone can provide. I am at a loss as to what to do. Here is a copy of the text file I am using. Thanks in advance.

CustID,FirstName,Last Name,Address1,Address2,City,State,Country,ProductID

101,William,Jones,1242 Elm St,,Chicago,IL,US,5462

102,Antoine,Sargeant,83 Main Ave,Apt 3A,Castle Rock,OR,US,13569

103,Linda,Montoya,51198 3rd Ave,,Brooklyn,NY,US,5462

104,Bernard,St John,Alwyn's Mews,128 Dennis Alley,London,,UK,9073-C

105,Knute,Olmstead,3135 Kirche,,Malmo,,SE,6215-G

106,Karen,Noyes,163 Morris AVe,,Denver,CO,US,45123

107,Sam,Ng,9081 Allard St,,San Lucia,CA,US,13569

108,Carl,Johnson,62161 3rd St,,Morningside,IN,US,5462

109,Janet,Smith,1531 Maple Grove Rd,,Maple Grove,MA,US,45123

110,Trevor,Beckwith,999 Archibald Ct,5G,Little Farthington,,UK,9073-B

111,Mark,Jonson,15245 Lingle Terrace,,Two Forks,AL,US,5462

112,Millie,Dingle,16 Sixth St,Ste. 11345,Austin,TX,US,5498

113,David,Winegard,7045 Portman Dr.,,East Millersville,OH,US,13569

114,Nathan,MacDonald,61 Freedom Pl,,Carthage,MD,US,45123

115,Cathy,Walton,2 Main St,,Four Mile, SD,US,5462

116,Stephen,Morrisson,712 Lovely Dr,,Allard,MO,US,5462

117,Jacques,Millefois,77B Ave Fouchard,,Arles,,FR,6215-A

118,Andy,Dorn,359 Park Ln,,Memphis,TN,US,13569

119,Tonya,Williams,793 Forest Dr,213,Dallas,Morris Glen,NJ,US,5462

Recommended Answers

All 18 Replies

Line 205? Where's line 205? Please repost using Java code tags. which will add line numbers, or highlight line 205 in red.

[code=JAVA] // paste code here

[/code]

Sorry about that. I didn't think about adding the line numbers. Here it is again...hopefully.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;

public class CustomerInfo extends JFrame implements ActionListener
{
	//construct components
	JTextPane textPane = new JTextPane();

	//initialize data in arrays
	public void readFile()
	{
		BufferedReader br = null;
		String[] custID = new String[100];
		String[] firstName = new String[100];
		String[] lastName = new String[100];
		String[] addressOne = new String[100];
		String[] addressTwo = new String[100];
		String[] myCity = new String[100];
		String[] myState = new String[100];
		String[] myCountry = new String[100];
		String[] productionID = new String[100];
		int num = 0;

		try
		{
			br = new BufferedReader(new FileReader("Database.txt"));
			String line = null;

			while ((line = br.readLine()) != null)
			{
				String[] values = line.split(",");
				if (values.length > 1)
				{
					custID[num] = values[0];
					firstName[num] = values[1];
					lastName[num] = values[2];
					addressOne[num] = values[3];
					addressTwo[num] = values[4];
					myCity[num] = values[5];
					myState[num] = values[6];
					myCountry[num] = values[7];
					productionID[num] = values[8];
					num++;
				}
			}
		}
		catch (FileNotFoundException ex)
		{
			ex.printStackTrace();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if (br != null)
				br.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}

	//construct instance of CustomerInfo
	public CustomerInfo()
	{
		super("Customer Information Database");
	}

	//create the menu system
	public JMenuBar createMenuBar()
	{
		//create an instance of the menu
		JMenuBar mnuBar = new JMenuBar();
		setJMenuBar(mnuBar);

		//construct and populate the File menu
		JMenu mnuFile = new JMenu("File", true);
			mnuFile.setMnemonic(KeyEvent.VK_F);
			mnuFile.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuFile);

		JMenuItem mnuFileExit = new JMenuItem("Exit");
			mnuFileExit.setMnemonic(KeyEvent.VK_X);
			mnuFileExit.setDisplayedMnemonicIndex(1);
			mnuFile.add(mnuFileExit);
			mnuFileExit.setActionCommand("Exit");
			mnuFileExit.addActionListener(this);

		//construct and populate the Edit menu
		JMenu mnuEdit = new JMenu("Edit", true);
			mnuEdit.setMnemonic(KeyEvent.VK_E);
			mnuEdit.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuEdit);

		JMenu mnuEditSearch = new JMenu("Search");
			mnuEditSearch.setMnemonic(KeyEvent.VK_R);
			mnuEditSearch.setDisplayedMnemonicIndex(3);
			mnuEdit.add(mnuEditSearch);

		JMenuItem mnuEditSearchByName = new JMenuItem("by Last Name");
			mnuEditSearchByName.setMnemonic(KeyEvent.VK_L);
			mnuEditSearchByName.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByName);
			mnuEditSearchByName.setActionCommand("last");
			mnuEditSearchByName.addActionListener(this);

		JMenuItem mnuEditSearchByProdNum = new JMenuItem("by Product Number");
			mnuEditSearchByProdNum.setMnemonic(KeyEvent.VK_P);
			mnuEditSearchByProdNum.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByProdNum);
			mnuEditSearchByProdNum.setActionCommand("production");
			mnuEditSearchByProdNum.addActionListener(this);

		JMenuItem mnuEditSearchByState = new JMenuItem("by State");
			mnuEditSearchByState.setMnemonic(KeyEvent.VK_S);
			mnuEditSearchByState.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByState);
			mnuEditSearchByState.setActionCommand("state");
			mnuEditSearchByState.addActionListener(this);

		return mnuBar;
	}

	//create the content pane
	public Container createContentPane()
	{

		//construct and populate the north panel
		JPanel northPanel = new JPanel();
			northPanel.setLayout(new FlowLayout());

		//create the JTextPane and center panel
		JPanel centerPanel = new JPanel();
			setTabsAndStyles(textPane);
			textPane = addTextToTextPane();
			JScrollPane scrollPane = new JScrollPane(textPane);
				scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
				scrollPane.setPreferredSize(new Dimension(500, 200));
			centerPanel.add(scrollPane);

		//create Container and set attributes
		Container c = getContentPane();
			c.setLayout(new BorderLayout(10,10));
			c.add(northPanel,BorderLayout.NORTH);
			c.add(centerPanel,BorderLayout.CENTER);

		return c;
	}

	//method to create tab stops and set font styles
	protected void setTabsAndStyles(JTextPane textPane)
	{
		//create Tab Stops
		TabStop[] tabs = new TabStop[2];
			tabs[0] = new TabStop(200, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[1] = new TabStop(350, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
		TabSet tabset = new TabSet(tabs);

		//set Tab Style
		StyleContext tabStyle = StyleContext.getDefaultStyleContext();
		AttributeSet aset = tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
		textPane.setParagraphAttributes(aset, false);

		//set Font Style
		Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

		Style regular = textPane.addStyle("regular", fontStyle);
		StyleConstants.setFontFamily(fontStyle, "SansSerif");

		Style s = textPane.addStyle("italic", regular);
		StyleConstants.setItalic(s, true);

		s = textPane.addStyle("bold", regular);
		StyleConstants.setBold(s, true);

		s = textPane.addStyle("large", regular);
		StyleConstants.setFontSize(s, 16);
	}

	//method to add new text to the JTextPane
	public JTextPane addTextToTextPane()
	{
		Document doc = textPane.getDocument();
		try
		{
			//clear previous text
			doc.remove(0, doc.getLength());

			//insert title
			doc.insertString(0,"CUST ID\tLAST NAME\tFIRST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//insert detail
			for (int j = 0; j < lastName.length; j++)
			{
				doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
				doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}

		return textPane;
	}

	//event to process user clicks
	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();

		//user clicks Exit on the File menu
		if (arg == "Exit")
			System.exit(0);

		//user clicks title on the Search submenu
		if (arg == "last")
			search(arg, last);

		//user clicks studio on the Search submenu
		if (arg == "production")
			search(arg, production);

		//user clicks state on the Search submenu
		if (arg == "state")
			search(arg, state);
	}

	//method to search arrays
	public void search(String searchField, String searchArray[])
	{
		try
		{
			Document doc = textPane.getDocument();	//assign text to document object
			doc.remove(0,doc.getLength());	//clear previous text

			//display column titles
			doc.insertString(0,"CUST ID\tLAST NAME\tFIRST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//prompt user for search data
			String search = JOptionPane.showInputDialog(null, "Please enter the "+ searchField);
			boolean found = false;

			//search arrays
			for (int i = 0; i < lastName.length; i++)
			{
				if (search.compareTo(searchArray[i])==0)
				{
					doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
					doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
					found = true;
				}
			}
			if (found == false)
			{
				JOptionPane.showMessageDialog(null, "Your search produced no results.", "No results found",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}
	}

	//main method executes at run time
	public static void main(String args[])
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		CustomerInfo f = new CustomerInfo();
		f.readFile();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setJMenuBar(f.createMenuBar());
		f.setContentPane(f.createContentPane());
		f.setSize(600,375);
		f.setVisible(true);
	}
}

You have a scoping issue. You define lastName in function readFile. lastName is not a class data member, so it goes out of scope once the readFile function is over. You try to use it in the addTextToTextPane function. You can't do that. If you intend lastName to be global/class variable, you should declare it at a global scale. Anything initially declared inside of a function is not a global/class variable.

That's the conclusion that I was thinking about also...I am at a lost as to the best way to go about making those array variables global...I dont suppose you have any suggestions? One example would be a good start for me to learn from.

public class anExample{
private Object obj; 
private static Object obj2;
public Object obj3;
public static Object obj4;

public static void main(String[] args){
}

//other methods

}

From a method inside the class with an instance of anExample:
You can refer to (use) obj and obj3.

From a static method inside the class without an instance of anExample:
You can use obj2 and obj4. Being static means the class has one copy of them that is shared by the entire class.

From a method inside a different class, with an instance of anExample:
You can refer to obj3

From a method inside a different class, without an instance of anExample:
you can refer to obj4


So the answer to your question would be the following, although I didn't look at your code. Either use a public or protected variable in your main driver class (the one thats run when you first start the program), use a private instance variable and provide accessors and mutators, or you could use a static variable. In either case, if you wanted easy access to the variable in both of your classes, consider using constructors that take the parameter as an argument.

Thanks for the pointers...I think I am going to try something like this:

public class Global {
     public static int = 37;
     public static String s = "aaa";
}

public class test {
     public static void main(Strings args[])
     {
          Global.x = Global.x + 100;
          Global.s = "bbb";
     }
}

From what I see in this example, I will go ahead and implement something similar and rewrite my array varaiables accordingly......I'll reply with the results.

Yes, the above example will work, as long as you declare x properly. It should say public static int x = 37;

Thanks for the pointers...I think I am going to try something like this:

public class Global {
     public static int = 37;
     public static String s = "aaa";
}

public class test {
     public static void main(Strings args[])
     {
          Global.x = Global.x + 100;
          Global.s = "bbb";
     }
}

From what I see in this example, I will go ahead and implement something similar and rewrite my array varaiables accordingly......I'll reply with the results.

Why create a new class? How about just changing lines 18 - 28 from your original code and split them up? Put the declarations at the class level, put the rest of the lines in the constructor or keep it them in the readFile function...

public class CustomerInfo extends JFrame implements ActionListener
{
		String[] custID;
		String[] firstName;
		String[] lastName;
		String[] addressOne;
		String[] addressTwo;
		String[] myCity;
		String[] myState;
		String[] myCountry;
		String[] productionID;


         public void readFile()
	{
		BufferedReader br = null;
		custID = new String[100];
		firstName = new String[100];
		lastName = new String[100];
		addressOne = new String[100];
		addressTwo = new String[100];
		myCity = new String[100];
		myState = new String[100];
		myCountry = new String[100];
		productionID = new String[100];
		int num = 0;

                // rest of code
        }
}

Now you can use the variables in lines 3 - 11 globally. Or again, if you are only calling readFile once, you can put the new commands in the constructor.

@ Vernon: I got the impression that he isn't creating a new class, he was just giving an example of what he thought the concepts were, and he's going to use those concepts in the class he currently has. No?

"Global" is not the same as instance level scoping. Careful about using those terms interchangeably.

Scoping issue aside, I have to wonder why you nine different unrelated arrays to hold the properties of what should probably be a one dimensional array of objects that contain that data?

Well, I got the program working by creating a seperate class that defines the individual arrays Globally. I mainly had to use seperate arrays to hold individual data because of 3 Searches performed by using a particular field...either by Last Name, Production ID or State.

Right, wrong or indifferent...this code now works. Now, I just have to format the Pane so that all of the data fits....thanks again for everyone's help and insight. I appreciate the information and will use the ideas.

I think you could use a 3D KD tree for that. Well, actually, not really, since a KD tree works by analyzing the first key, then second, then third, etc, depending on what level you're on. But I don't see why you can't put all the data into one array, then simply search through the data according to whatever characteristic you're looking for. And Ezzaral, my professors always use Global to refer to what would be the same as a 'static' member of a class in Java. But if you're saying an instance of a class doesn't contain Global variables (I mean, that Global variables aren't class instances), I agree.

I changed it all to prevent me from having to create a seperate class file and pretty'd up the output display. Here's my final result that works like a charm:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;

public class CustomerInfo extends JFrame implements ActionListener
{
	//construct components
	JTextPane textPane = new JTextPane();
	String[] custID;
	String[] firstName;
	String[] lastName;
	String[] addressOne;
	String[] addressTwo;
	String[] myCity;
	String[] myState;
	String[] myCountry;
	String[] productionID;

	//initialize data in arrays
	public void readFile()
	{
		BufferedReader br = null;
		custID = new String[20];
		firstName = new String[20];
		lastName = new String[20];
		addressOne = new String[20];
		addressTwo = new String[20];
		myCity = new String[20];
		myState = new String[20];
		myCountry = new String[20];
		productionID = new String[20];
		int num = 0;

		try
		{
			br = new BufferedReader(new FileReader("Database.txt"));
			String line = null;

			while ((line = br.readLine()) != null)
			{
				String[] values = line.split(",");
				if (values.length > 1)
				{
					custID[num] = values[0];
					firstName[num] = values[1];
					lastName[num] = values[2];
					addressOne[num] = values[3];
					addressTwo[num] = values[4];
					myCity[num] = values[5];
					myState[num] = values[6];
					myCountry[num] = values[7];
					productionID[num] = values[8];
					num++;
				}
			}
		}
		catch (FileNotFoundException ex)
		{
			ex.printStackTrace();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if (br != null)
				br.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}

	//construct instance of CustomerInfo
	public CustomerInfo()
	{
		super("Customer Information Database");
	}

	//create the menu system
	public JMenuBar createMenuBar()
	{
		//create an instance of the menu
		JMenuBar mnuBar = new JMenuBar();
		setJMenuBar(mnuBar);

		//construct and populate the File menu
		JMenu mnuFile = new JMenu("File", true);
			mnuFile.setMnemonic(KeyEvent.VK_F);
			mnuFile.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuFile);

		JMenuItem mnuFileExit = new JMenuItem("Exit");
			mnuFileExit.setMnemonic(KeyEvent.VK_X);
			mnuFileExit.setDisplayedMnemonicIndex(1);
			mnuFile.add(mnuFileExit);
			mnuFileExit.setActionCommand("Exit");
			mnuFileExit.addActionListener(this);

		//construct and populate the Edit menu
		JMenu mnuEdit = new JMenu("Edit", true);
			mnuEdit.setMnemonic(KeyEvent.VK_E);
			mnuEdit.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuEdit);

		JMenu mnuEditSearch = new JMenu("Search");
			mnuEditSearch.setMnemonic(KeyEvent.VK_R);
			mnuEditSearch.setDisplayedMnemonicIndex(3);
			mnuEdit.add(mnuEditSearch);

		JMenuItem mnuEditSearchByName = new JMenuItem("by Last Name");
			mnuEditSearchByName.setMnemonic(KeyEvent.VK_L);
			mnuEditSearchByName.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByName);
			mnuEditSearchByName.setActionCommand("by Last Name");
			mnuEditSearchByName.addActionListener(this);

		JMenuItem mnuEditSearchByProdNum = new JMenuItem("by Product Number");
			mnuEditSearchByProdNum.setMnemonic(KeyEvent.VK_P);
			mnuEditSearchByProdNum.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByProdNum);
			mnuEditSearchByProdNum.setActionCommand("by Product Number");
			mnuEditSearchByProdNum.addActionListener(this);

		JMenuItem mnuEditSearchByState = new JMenuItem("by State");
			mnuEditSearchByState.setMnemonic(KeyEvent.VK_S);
			mnuEditSearchByState.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByState);
			mnuEditSearchByState.setActionCommand("by State");
			mnuEditSearchByState.addActionListener(this);

		return mnuBar;
	}

	//create the content pane
	public Container createContentPane()
	{

		//construct and populate the north panel
		JPanel northPanel = new JPanel();
			northPanel.setLayout(new FlowLayout());

		//create the JTextPane and center panel
		JPanel centerPanel = new JPanel();
			setTabsAndStyles(textPane);
			textPane = addTextToTextPane();
			JScrollPane scrollPane = new JScrollPane(textPane);
				scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
				scrollPane.setPreferredSize(new Dimension(1000, 325));
			centerPanel.add(scrollPane);

		//create Container and set attributes
		Container c = getContentPane();
			c.setLayout(new BorderLayout(10,10));
			c.add(northPanel,BorderLayout.NORTH);
			c.add(centerPanel,BorderLayout.CENTER);

		return c;
	}

	//method to create tab stops and set font styles
	protected void setTabsAndStyles(JTextPane textPane)
	{

		//create Tab Stops
		TabStop[] tabs = new TabStop[9];
			tabs[0] = new TabStop(10, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[1] = new TabStop(75, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[2] = new TabStop(175, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[3] = new TabStop(275, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[4] = new TabStop(400, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[5] = new TabStop(500, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[6] = new TabStop(600, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[7] = new TabStop(700, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[8] = new TabStop(800, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
		TabSet tabset = new TabSet(tabs);

		//set Tab Style
		StyleContext tabStyle = StyleContext.getDefaultStyleContext();
		AttributeSet aset = tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
		textPane.setParagraphAttributes(aset, false);

		//set Font Style
		Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

		Style regular = textPane.addStyle("regular", fontStyle);
		StyleConstants.setFontFamily(fontStyle, "SansSerif");

		Style s = textPane.addStyle("italic", regular);
		StyleConstants.setItalic(s, true);

		s = textPane.addStyle("bold", regular);
		StyleConstants.setBold(s, true);

		s = textPane.addStyle("large", regular);
		StyleConstants.setFontSize(s, 16);
	}

	//method to add new text to the JTextPane
	public JTextPane addTextToTextPane()
	{
		Document doc = textPane.getDocument();
		try
		{
			//clear previous text
			doc.remove(0, doc.getLength());

			//insert title
			doc.insertString(0,"CUST ID\tFIRST NAME\tLAST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//insert detail
			for (int j = 0; j < custID.length; j++)
			{
				doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
				doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}

		return textPane;
	}

	//event to process user clicks
	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();

		//user clicks Exit on the File menu
		if (arg == "Exit")
			System.exit(0);

		//user clicks lastName on the Search submenu
		if (arg == "by Last Name")
			search(arg, lastName);

		//user clicks production on the Search submenu
		if (arg == "by Product Number")
			search(arg, productionID);

		//user clicks state on the Search submenu
		if (arg == "by State")
			search(arg, myState);
	}

	//method to search arrays
	public void search(String searchField, String searchArray[])
	{
		try
		{
			//assign text to document object
			Document doc = textPane.getDocument();

			//clear previous text
			doc.remove(0,doc.getLength());

			//display column titles
			doc.insertString(0,"CUST ID\tFIRST NAME\tLAST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//prompt user for search data
			String search = JOptionPane.showInputDialog(null, "Please enter the "+ searchField);
			boolean found = false;

			//search arrays
			for (int i = 0; i < lastName.length; i++)
			{
				if (search.compareTo(searchArray[i])==0)
				{
					doc.insertString(doc.getLength(), custID[i] + "\t", textPane.getStyle("bold"));
					doc.insertString(doc.getLength(), firstName[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), lastName[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressOne[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressTwo[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCity[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myState[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCountry[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), productionID[i] + "\n", textPane.getStyle("regular"));
					found = true;
				}
			}
			if (found == false)
			{
				JOptionPane.showMessageDialog(null, "Your search produced no results.", "No results found",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}
	}

	//main method executes at run time
	public static void main(String args[])
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		CustomerInfo f = new CustomerInfo();
		f.readFile();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setJMenuBar(f.createMenuBar());
		f.setContentPane(f.createContentPane());
		f.setSize(1100,500);
		f.setVisible(true);
	}
}

I want to thank everyone again for all of your help.

Just picked up Java myself and for the sake of learning I tried this example and for some reason I keep getting the following error when I try to run this program, it compiles OK but I get the this error at run-time

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8

Thanks
Robert

I changed it all to prevent me from having to create a seperate class file and pretty'd up the output display. Here's my final result that works like a charm:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;

public class CustomerInfo extends JFrame implements ActionListener
{
	//construct components
	JTextPane textPane = new JTextPane();
	String[] custID;
	String[] firstName;
	String[] lastName;
	String[] addressOne;
	String[] addressTwo;
	String[] myCity;
	String[] myState;
	String[] myCountry;
	String[] productionID;

	//initialize data in arrays
	public void readFile()
	{
		BufferedReader br = null;
		custID = new String[20];
		firstName = new String[20];
		lastName = new String[20];
		addressOne = new String[20];
		addressTwo = new String[20];
		myCity = new String[20];
		myState = new String[20];
		myCountry = new String[20];
		productionID = new String[20];
		int num = 0;

		try
		{
			br = new BufferedReader(new FileReader("Database.txt"));
			String line = null;

			while ((line = br.readLine()) != null)
			{
				String[] values = line.split(",");
				if (values.length > 1)
				{
					custID[num] = values[0];
					firstName[num] = values[1];
					lastName[num] = values[2];
					addressOne[num] = values[3];
					addressTwo[num] = values[4];
					myCity[num] = values[5];
					myState[num] = values[6];
					myCountry[num] = values[7];
					productionID[num] = values[8];
					num++;
				}
			}
		}
		catch (FileNotFoundException ex)
		{
			ex.printStackTrace();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if (br != null)
				br.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}

	//construct instance of CustomerInfo
	public CustomerInfo()
	{
		super("Customer Information Database");
	}

	//create the menu system
	public JMenuBar createMenuBar()
	{
		//create an instance of the menu
		JMenuBar mnuBar = new JMenuBar();
		setJMenuBar(mnuBar);

		//construct and populate the File menu
		JMenu mnuFile = new JMenu("File", true);
			mnuFile.setMnemonic(KeyEvent.VK_F);
			mnuFile.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuFile);

		JMenuItem mnuFileExit = new JMenuItem("Exit");
			mnuFileExit.setMnemonic(KeyEvent.VK_X);
			mnuFileExit.setDisplayedMnemonicIndex(1);
			mnuFile.add(mnuFileExit);
			mnuFileExit.setActionCommand("Exit");
			mnuFileExit.addActionListener(this);

		//construct and populate the Edit menu
		JMenu mnuEdit = new JMenu("Edit", true);
			mnuEdit.setMnemonic(KeyEvent.VK_E);
			mnuEdit.setDisplayedMnemonicIndex(0);
			mnuBar.add(mnuEdit);

		JMenu mnuEditSearch = new JMenu("Search");
			mnuEditSearch.setMnemonic(KeyEvent.VK_R);
			mnuEditSearch.setDisplayedMnemonicIndex(3);
			mnuEdit.add(mnuEditSearch);

		JMenuItem mnuEditSearchByName = new JMenuItem("by Last Name");
			mnuEditSearchByName.setMnemonic(KeyEvent.VK_L);
			mnuEditSearchByName.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByName);
			mnuEditSearchByName.setActionCommand("by Last Name");
			mnuEditSearchByName.addActionListener(this);

		JMenuItem mnuEditSearchByProdNum = new JMenuItem("by Product Number");
			mnuEditSearchByProdNum.setMnemonic(KeyEvent.VK_P);
			mnuEditSearchByProdNum.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByProdNum);
			mnuEditSearchByProdNum.setActionCommand("by Product Number");
			mnuEditSearchByProdNum.addActionListener(this);

		JMenuItem mnuEditSearchByState = new JMenuItem("by State");
			mnuEditSearchByState.setMnemonic(KeyEvent.VK_S);
			mnuEditSearchByState.setDisplayedMnemonicIndex(3);
			mnuEditSearch.add(mnuEditSearchByState);
			mnuEditSearchByState.setActionCommand("by State");
			mnuEditSearchByState.addActionListener(this);

		return mnuBar;
	}

	//create the content pane
	public Container createContentPane()
	{

		//construct and populate the north panel
		JPanel northPanel = new JPanel();
			northPanel.setLayout(new FlowLayout());

		//create the JTextPane and center panel
		JPanel centerPanel = new JPanel();
			setTabsAndStyles(textPane);
			textPane = addTextToTextPane();
			JScrollPane scrollPane = new JScrollPane(textPane);
				scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
				scrollPane.setPreferredSize(new Dimension(1000, 325));
			centerPanel.add(scrollPane);

		//create Container and set attributes
		Container c = getContentPane();
			c.setLayout(new BorderLayout(10,10));
			c.add(northPanel,BorderLayout.NORTH);
			c.add(centerPanel,BorderLayout.CENTER);

		return c;
	}

	//method to create tab stops and set font styles
	protected void setTabsAndStyles(JTextPane textPane)
	{

		//create Tab Stops
		TabStop[] tabs = new TabStop[9];
			tabs[0] = new TabStop(10, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[1] = new TabStop(75, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[2] = new TabStop(175, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[3] = new TabStop(275, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[4] = new TabStop(400, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[5] = new TabStop(500, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[6] = new TabStop(600, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[7] = new TabStop(700, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
			tabs[8] = new TabStop(800, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
		TabSet tabset = new TabSet(tabs);

		//set Tab Style
		StyleContext tabStyle = StyleContext.getDefaultStyleContext();
		AttributeSet aset = tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
		textPane.setParagraphAttributes(aset, false);

		//set Font Style
		Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

		Style regular = textPane.addStyle("regular", fontStyle);
		StyleConstants.setFontFamily(fontStyle, "SansSerif");

		Style s = textPane.addStyle("italic", regular);
		StyleConstants.setItalic(s, true);

		s = textPane.addStyle("bold", regular);
		StyleConstants.setBold(s, true);

		s = textPane.addStyle("large", regular);
		StyleConstants.setFontSize(s, 16);
	}

	//method to add new text to the JTextPane
	public JTextPane addTextToTextPane()
	{
		Document doc = textPane.getDocument();
		try
		{
			//clear previous text
			doc.remove(0, doc.getLength());

			//insert title
			doc.insertString(0,"CUST ID\tFIRST NAME\tLAST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//insert detail
			for (int j = 0; j < custID.length; j++)
			{
				doc.insertString(doc.getLength(), custID[j] + "\t", textPane.getStyle("bold"));
				doc.insertString(doc.getLength(), firstName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), lastName[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressOne[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), addressTwo[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCity[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myState[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), myCountry[j] + "\t", textPane.getStyle("regular"));
				doc.insertString(doc.getLength(), productionID[j] + "\n", textPane.getStyle("regular"));
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}

		return textPane;
	}

	//event to process user clicks
	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();

		//user clicks Exit on the File menu
		if (arg == "Exit")
			System.exit(0);

		//user clicks lastName on the Search submenu
		if (arg == "by Last Name")
			search(arg, lastName);

		//user clicks production on the Search submenu
		if (arg == "by Product Number")
			search(arg, productionID);

		//user clicks state on the Search submenu
		if (arg == "by State")
			search(arg, myState);
	}

	//method to search arrays
	public void search(String searchField, String searchArray[])
	{
		try
		{
			//assign text to document object
			Document doc = textPane.getDocument();

			//clear previous text
			doc.remove(0,doc.getLength());

			//display column titles
			doc.insertString(0,"CUST ID\tFIRST NAME\tLAST NAME\tADDRESS 1\tADDRESS 2\tCITY\tSTATE\tCOUNTRY\tPRODUCTION ID\n",textPane.getStyle("large"));

			//prompt user for search data
			String search = JOptionPane.showInputDialog(null, "Please enter the "+ searchField);
			boolean found = false;

			//search arrays
			for (int i = 0; i < lastName.length; i++)
			{
				if (search.compareTo(searchArray[i])==0)
				{
					doc.insertString(doc.getLength(), custID[i] + "\t", textPane.getStyle("bold"));
					doc.insertString(doc.getLength(), firstName[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), lastName[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressOne[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), addressTwo[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCity[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myState[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), myCountry[i] + "\t", textPane.getStyle("regular"));
					doc.insertString(doc.getLength(), productionID[i] + "\n", textPane.getStyle("regular"));
					found = true;
				}
			}
			if (found == false)
			{
				JOptionPane.showMessageDialog(null, "Your search produced no results.", "No results found",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		catch (BadLocationException ble)
		{
			System.err.println("Couldn't insert text.");
		}
	}

	//main method executes at run time
	public static void main(String args[])
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		CustomerInfo f = new CustomerInfo();
		f.readFile();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setJMenuBar(f.createMenuBar());
		f.setContentPane(f.createContentPane());
		f.setSize(1100,500);
		f.setVisible(true);
	}
}

I want to thank everyone again for all of your help.

I haven't looked at this guy's code since I responded to this thread a while ago (and judging by what I said in my response, I didn't look too hard then, either) but if I were you, I wouldn't be using his code to learn about Java.

Would you happen to know what this error means?, I just don't see how the array is out of bounds...if my understanding is correct...I'm a veteran on visual basic and know a little of C++ but Java seems a bit confusing


Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8


Thanks
Rob


I haven't looked at this guy's code since I responded to this thread a while ago (and judging by what I said in my response, I didn't look too hard then, either) but if I were you, I wouldn't be using his code to learn about Java.

It means the code attempted to access the ninth element of an array that does not have nine elements. Your stack trace would also tell you what line that occurred on. It's probably on one of the lines in readFile() where the data is being put into the arrays after the split().

You are so freaking right, there were some empty commas and this caused the search to overlap..

Thanks a lot!!!


Rob.

It means the code attempted to access the ninth element of an array that does not have nine elements. Your stack trace would also tell you what line that occurred on. It's probably on one of the lines in readFile() where the data is being put into the arrays after the split().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.