Try updating the VendingMachineGUI class with this:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
public class VendingMachineGUI extends JFrame{
private JTextArea displayArea;
private JTextField CoinTextField;
private JButton CoinButton, saveButton, displayAllItemsButton,
findItemButton, updateButton, PurchaseButton;
private ArrayList<Dispenser> listRecords;
private int counter;
private Credit c;
public float totalCredit;
private Dispenser vendingitems[];
public static void main(String[] args) {
new VendingMachineGUI();
}
public VendingMachineGUI() {
setLayout(new FlowLayout());
CoinTextField = new JTextField(20);
CoinButton = new JButton("Add Coin");
CoinButton.setForeground(Color.blue);
saveButton = new JButton("Save Item");
saveButton.setForeground(Color.red);
displayAllItemsButton = new JButton("Display All Items!");
displayAllItemsButton.setForeground(Color.blue);
findItemButton = new JButton("Find Item ?");
updateButton = new JButton("Update List");
updateButton.setForeground(Color.blue);
displayArea = new JTextArea();
displayArea.setPreferredSize(new Dimension(400, 200));
displayArea.setBackground(Color.lightGray);
PurchaseButton = new JButton("Purchase Items!");
PurchaseButton.setForeground(Color.blue);
c = new Credit();
add(CoinButton);
add(CoinTextField);
add(saveButton);
add(displayAllItemsButton);
add(displayArea);
add(findItemButton);
add(updateButton);
add(PurchaseButton);
// saveButton.addActionListener(this);
// displayAllItemsButton.addActionListener(this);
// findItemButton.addActionListener(this);
// updateButton.addActionListener(this);
displayAllItemsButton.setEnabled(false);
findItemButton.setEnabled(false);
updateButton.setEnabled(false);
setTitle("*** Vending Machine ****");
setSize(450, 500);
setVisible(true);
CoinTextField.setText("0.0");
vendingitems = new Dispenser[8];
counter = 0;
CoinButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
totalCredit = c.addCredit();
//Execute when button is pressed
//System.out.println("Coin button pressed");
CoinTextField.setText(Float.toString(totalCredit));
}
});
}
}