@Override
	public void actionPerformed(ActionEvent e) 
	{
		
		//gets source of button click
		JButton button =(JButton) e.getSource();
		Dimension size = button.getSize();
		
		// gets the x,y coordinates of the button that was hit and an empty label
		int labelX = label.getX();
		int labelY = label.getY();
		int buttonX = button.getX();
		int buttonY = button.getY();
		
		// gets the index of the button from the array we created above
		int buttonPosX = buttonX/size.width;
		int buttonPosY = buttonY/size.height;
		int buttonIndex = pos[buttonPosY][buttonPosX];
		
		
		//possible positions around label
		boolean buttAboveBlank= (labelX==buttonX && (labelY-buttonY)==size.height);
		boolean buttBelowBlank= (labelX==buttonX && (labelY-buttonY)==-size.height);
		boolean buttLeftBlank= (labelY==buttonY && (labelX-buttonX)==size.width);
		boolean buttRightBlank= (labelY==buttonY && (labelX-buttonX)==-size.width);
		
		//above blank space
		if (buttAboveBlank)
		{
			swap(buttonIndex,buttonIndex+3,button);
		}
		//below blank space
		if (buttBelowBlank)
		{
			swap(buttonIndex,buttonIndex-3,button);
		}
		
		// left of the blank space
		if (buttLeftBlank)
		{
			swap(buttonIndex,buttonIndex+1,button);
		}
		// right of the blank space
		if (buttRightBlank)
		{
			swap(buttonIndex,buttonIndex-1,button);
		}
		
		
	}