I have my code set up so I can 1)select what image and 2)the coordinates of the mouse click where the image is going to be placed.

What it currently does it place the right image in the right coordiantes but if I click again somewhere else, it replaces the last image's coords with the new clicked coords.

What I need is that when I click on the canvas, it should place the image permanently and when I click again it places an entirely new image.

Inside the mouse click event

//set new tower coords
if (minY>200){
	int towerID=towers.getTowerId(towerx, towery)
	towers.setNewTower(towerType, towerx, towery);
	if (towerType==1)towerImage[towerID]=tower1;
	if (towerType==2)towerImage[towerID]=tower2;
	if (towerType==3)towerImage[towerID]=tower3;

Inside the paint method

if (setnewtower==true){
	int towerID=towers.getTowerId(towerx, towery)
	g.drawImage(towerImage[towerID], towerx, towery, observe);

How to create a new .drawImage while running the program?

This article has been dead for over six months. Start a new discussion instead.