| | |
Reading a txt file into a swing component
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 20
Reputation:
Solved Threads: 0
Hello, I was hoping that someone might be able to help me with this program:
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.
Java Syntax (Toggle Plain Text)
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.
Java Syntax (Toggle Plain Text)
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
•
•
Join Date: Jan 2008
Posts: 20
Reputation:
Solved Threads: 0
Sorry about that. I didn't think about adding the line numbers. Here it is again...hopefully.
Java Syntax (Toggle Plain Text)
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); } }
•
•
Join Date: Jan 2008
Posts: 3,817
Reputation:
Solved Threads: 501
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.
Last edited by VernonDozier; Nov 4th, 2008 at 4:33 pm.
•
•
Join Date: Sep 2008
Posts: 1,574
Reputation:
Solved Threads: 197
java Syntax (Toggle Plain Text)
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.
Last edited by BestJewSinceJC; Nov 4th, 2008 at 5:02 pm.
•
•
Join Date: Jan 2008
Posts: 20
Reputation:
Solved Threads: 0
Thanks for the pointers...I think I am going to try something like this:
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.
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Jan 2008
Posts: 3,817
Reputation:
Solved Threads: 501
•
•
•
•
Thanks for the pointers...I think I am going to try something like this:
Java Syntax (Toggle Plain Text)
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.
JAVA Syntax (Toggle Plain Text)
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. ![]() |
Similar Threads
- Homework Help (Java)
- Homework Help (Community Introductions)
Other Threads in the Java Forum
- Previous Thread: Accessing classes from xml settings
- Next Thread: convert nested for loop into nested while loop
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






