|
How do you make array's global? I have buttons, ints, etc being able to be read and manipulated from within an actionPerformed but when I declare and create a new instance of it within main class I cannot seem to use it within my action button routine. IE:
public class B2C5 extends JFrame implements ActionListener { String Catalog[][]; Action retaction; public B2C5() { Catalog = new String[7][5]; String Catalog[][]={{"DR800","Drills - Corded","3/8 Variable","139.99","Yes"}, {"DR700","Drills - Corded","3.2 amp","50.00","Yes"}, {"CS600","Circular Saw","18 volt","199.99","Yes"}, {"CS500","Circular Saw","14 volt","99.99","No"}, {"SD200","Sander","Palm","29.99","Yes"}, {"SD300","Sander","Orbital","59.95","Yes"}, {"GR200","Grinder","Rotary","89.95","No"}}; retaction=new RETAction(); } class RETAction extends AbstractAction { public RETAction() { super("Retail Customer", new ImageIcon("retail.png")); } public void actionPerformed (ActionEvent e) { //set textfields with array data Item1.setText(Catalog[0][1] + " " + Catalog[0][2] + " " + Catalog [0][3]); Item2.setText(Catalog[1][1] + " " + Catalog[1][2] + " " + Catalog [1][3]); } } }
Every time I click on the retail button I get nulls in my text fields. But if I put the array in the actionPerformed area it works. |