I am trying to make the number class become transparent when I click it and if it is clicked again, it returns to a solid color. However, the image of the number is variable (1 to 9) and the image was made within the program. If anyone could help, I thank you in advance.
Number Class:
One Class: - 1 to 9 class are similar, just have different image colors
public class Number extends Actor
{
//Variables used
private GreenfootImage img = getImage();
private boolean clicked = false;
private boolean match = false;
public int number;
One one = new One();
Two two = new Two();
Three three = new Three();
Four four = new Four();
Five five = new Five();
Six six = new Six();
Seven seven = new Seven();
Eight eight = new Eight();
Nine nine = new Nine();
public Number(int n)
{
number = n;
image();
}
public void act()
{
//If the one was clicked, clear the image and change the number to gray
if(Greenfoot.mouseClicked(this) && !clicked)
{
updateImage();
clicked = true;
}
//If the one was clicked, keep it clicked
if(!Greenfoot.mouseClicked(this) && clicked)
{
clicked = true;
}
//If the clicked one is clicked again, unclick it
if(Greenfoot.mouseClicked(this) && clicked)
{
resetImage();
clicked = false;
}
}
public void image()
{
if(number == 1) setImage(one.getImage());
if(number == 2) setImage(two.getImage());
if(number == 3) setImage(three.getImage());
if(number == 4) setImage(four.getImage());
if(number == 5) setImage(five.getImage());
if(number == 6) setImage(six.getImage());
if(number == 7) setImage(seven.getImage());
if(number == 8) setImage(eight.getImage());
if(number == 9) setImage(nine.getImage());
}
public void updateImage()
{
img.setTransparency(100);
}
public void resetImage()
{
img.setTransparency(255);
}
public int getActualHeight()
{
//Gets the height of a number's image
return getImage().getHeight();
}
public int getActualWidth()
{
//Gets the width of a number's image
return getImage().getWidth();
}
}public class One extends Actor
{
public One()
{
//Creates a 45x45 empty image
GreenfootImage tile = new GreenfootImage(45,45);
//Sets the font and its size
Font font = new Font("Courier", true, false, 45);
tile.setFont(font);
//Frames the tile with a square
tile.setColor(Color.GRAY);
tile.drawRect(0, 0, 45, 45);
//Displays the number one
tile.setColor(Color.BLACK);
tile.drawString("1",11,38);
//Sets the image of the tile
setImage(tile);
}
}

