public void mouseClicked(MouseEvent e) {
store clickedStore = null;
for (int i = 0; i < stores.length; i++) {
if (stores[i].isClicked(e.getX(), e.getY())) {
clickedStore = stores[i];
break;
}
}
}
Is it possible to display the result of the above loop as a string? I have tried various options but none have worked. It always results in the fact that a custom class cannot be converted to a string.
I have created my own class as shown below.
class store{
String name;
int x, y, width, height, centerX, centerY;
public store(String storeName,
int storeX,
int storeY,
int storeWidth,
int storeHeight,
int storeCenterX,
int storeCenterY) {
name = storeName;
x = storeX;
y = storeY;
width = storeWidth;
height = storeHeight;
centerX = storeCenterX;
centerY = storeCenterY;
}
store Asda = new store("Asda",100,100,40,40,120,120);
store Tesco = new store("Tesco",200,200,40,40,220,220);
store Morrisons = new store("Morrisons",400,400,40,40,220,220);
store[] stores = {Asda,Tesco,Morrisons};
I would like to display the result of the store I click on which is what the program is made for, however I cannot display the result of the aforementioned loop.
PLEASE HELP!