I want to get the position of the JButton
to have the return a value. I need the value to print out the element in an array list. I have ten elements in the array list. A GridLayout(0,2)
was used to layout the buttons.
So what should I do?
for(int i=0;i<item.size();i++)
{
JButton btn1= new JButton(item.get(i).print());
btn1.setPreferredSize(new Dimension(300,40));
panel2.setLayout(new GridLayout(0,2));
panel2.add(btn1, BorderLayout.NORTH);
content.add(panel2, BorderLayout.NORTH);
}
public Food selectFood(int input)
{
int get=0;
if(input>0 && input< 11)
{
item.get(input-1);
}
want to get the position as an input to print the selected item.