ok here is the class I am having issues with
CODE
class Program
{
static int counter = 0;
public void runProgram()
{
Inventory dvd = new Inventory(); //Create an Inventory Object
JFrame gui = new JFrame("Inventory Program Part 4"); //Create Main Frame
gui.setSize(600, 500);
gui.setVisible(true);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel noticePanel = new JPanel(); //Create panels to display text
JPanel headingPanel = new JPanel();
//JPanel itemInfoPanel = new JPanel();
JTextField itemNumber = new JTextField();
JTextField itemTitle = new JTextField();
JTextField itemUnits = new JTextField();
JTextField itemPrice = new JTextField();
JTextField itemTotal = new JTextField();
JTextField itemLength = new JTextField();
JPanel totalPanel = new JPanel();
JButton next = new JButton("Next Item"); //create the buttons
JButton first = new JButton("First Item");
JButton previous = new JButton("Previous Item");
JButton last = new JButton("Last Item");
next.setPreferredSize(new Dimension(100, 25));
first.setPreferredSize(new Dimension(125, 25));
previous.setPreferredSize(new Dimension(150, 25));
last.setPreferredSize(new Dimension(100, 25));
JButton addItem = new JButton("Add Item");
JButton modifyItem = new JButton("Modify Item");
JButton deleteItem = new JButton("Delete Item");
Icon companyLogo = new ImageIcon("logo.jpg"); //load the company logo image
JLabel logo = new JLabel(companyLogo);
logo.setIcon(companyLogo);
logo.setToolTipText("My Company is awsome");
next.addActionListener(new ActionListener() //next button action control
{
public void actionPerformed(ActionEvent evt)
{
counter++;
if(counter < 0) //return to last item if under
counter = dvd.movie.length-1;
if(counter >= dvd.movie.length) //return to first item if over
counter = 0;
}
});
first.addActionListener(new ActionListener() //next button action control
{
public void actionPerformed(ActionEvent evt)
{
counter = 0;
}
});
previous.addActionListener(new ActionListener() //next button action control
{
public void actionPerformed(ActionEvent evt)
{
counter--;
if(counter < 0) //return to last item if under
counter = dvd.movie.length-1;
if(counter >= dvd.movie.length) //return to first item if over
counter = 0;
}
});
last.addActionListener(new ActionListener() //next button action control
{
public void actionPerformed(ActionEvent evt)
{
counter = -1;
if(counter < 0) //return to last item if under
counter = dvd.movie.length-1;
if(counter >= dvd.movie.length) //return to first item if over
counter = 0;
}
});
addItem.addActionListener(new ActionListener() //next button action control
{
public void actionPerformed(ActionEvent evt)
{
itemTitle.setText(dvd.title(counter));
itemUnits.setText(dvd.units(counter));
itemPrice.setText(dvd.price(counter));
itemTotal.setText(dvd.total(counter));
itemLength.setText(dvd.length(counter));
}
});
FlowLayout layout = new FlowLayout(); //setup layout manager for frame
gui.setLayout(layout);
JTextArea notice = new JTextArea(1,1); //create text areas to display text
JTextArea heading = new JTextArea(1,1);
//JTextArea info = new JTextArea(1, 1);
JTextArea total = new JTextArea(1, 1);
heading.setSize(1, 1);
gui.add(logo);
gui.add(noticePanel); //add panels and button to the gui
gui.add(headingPanel);
//gui.add(itemInfoPanel);
gui.add(itemNumber);
gui.add(itemTitle);
gui.add(itemUnits);
gui.add(itemPrice);
gui.add(itemTotal);
gui.add(itemLength);
gui.add(totalPanel);
gui.add(first, layout);
gui.add(previous, layout);
gui.add(next, layout);
gui.add(last, layout);
gui.add(addItem, layout);
gui.add(modifyItem, layout);
gui.add(deleteItem, layout);
noticePanel.add(notice); //put the information from other methods into gui
headingPanel.add(heading);
//itemInfoPanel.add(info);
totalPanel.add(total);
//*****************************************************
//To allow access to its methods
dvd.fillArray(); //populate and sort the array of items
dvd.sortArray();
notice.setText(dvd.printNotice()); //print notice and heading
heading.setText(dvd.printHeadings());
total.setText(dvd.calculateGrandTotal()); //print grand total
for(;;) //loop to print items one at a time finally..
{
//Print out the items in the inventory
itemNumber.setText(dvd.number(counter));
itemTitle.setText(dvd.title(counter));
itemUnits.setText(dvd.units(counter));
itemPrice.setText(dvd.price(counter));
itemTotal.setText(dvd.total(counter));
itemLength.setText(dvd.length(counter));
}
}
}
In the first line of the method I create dvd, which is a new inventory object. I can reference it just fine down in the for loop at the bottom. What it won't let me do is reference dvd from inside the action listeners. Eclipse tells me I have to set dvd to final in order to refer dvd from within those.
The same goes for the one action listener named addItem. I was going to try and work with all the JTextfields from that one, but I am getting the same error there.