I have been creating a Monopoly game, and while creating the graphical interface I added a panel in which an image is drawn for each bought territory.
Everything works well so far, but my problems started when I tried to delete the Image from the panel when I sell the territory.I have no Idea how to achieve that.
This is the code for the Image drawing when player 1 buys a territory:
if(property.Properties[i][0] == 1){
if (y >= 390){
x = 140;
y = 40;
}
ImageIcon a = new ImageIcon(this.getClass().getResource("../Imagini/Headers/" + headers[i] +".jpg"));
icons = a.getImage();
g.drawImage(icons, x, y, null);
y +=25;
}
The image should be erased when the position of the player is set to 0.
How can I erase the Image when I sell it?
Is there a method that does that?
If not can you suggest an alternative way for achieving this?
put this Icon/ImageIcon to the JLabel#setIcon(myIcon), and this/these
JLabel(s) place by using LayoutManger to the JPanel,