I'm working on an EPOS system, and as part of the program, I am generating a GridLayout of all items that are stored in an ArrayList. Within the items ArrayList, all the objects are stored with their necessary member variables, such as name, barcode and price. I have currently made it so that the grid is populated, however the buttons are action-less, and I am quite unsure how to handle the data from the classes, is there perhaps some way to assign the values of the current item object that is being iterated over onto the button being made? As each button is made by my code, and is not "hand made". The relevant code is as below:
public class gridCreator extends JFrame {
ObjectCreator obj = new ObjectCreator();
GridLayout itemGrid = new GridLayout();
JFrame frame = new JFrame("pls work");
static gridCreator instance;
public static void main(String[] args) throws FileNotFoundException {
instance = new gridCreator();
instance.createGrids();
instance.createAndShowGUI();
}
public void createGrids() throws FileNotFoundException{
obj.loadItems();
itemGrid.setColumns(20);
itemGrid.setRows(4);
for (ObjectCreator.Item item : obj.items){
addComponentsToPane(item);
}
}
private void addComponentsToPane(ObjectCreator.Item item) {
JButton button = new JButton(item.getName());
frame.add(button);
}
As a side note, the ObjectCreator class is where the objects themselves are made.