First Of All, you haven't told where did the "block" in the if statement came from. What you may need to do, is:
public void swap(){
for(Entity en:entityList){
if((en instanceof Block)&&(en.position.equals(agent.position)){
// ^here is "en" instead of block
System.out.println("Agent overlab block: "+en);
en.previousPosition=new Dimension(
en.position.width,
en.position.height);
en.setPosition(agent.previousPosition);
}
}
}
At last, you may use java.awt.Point instead of Dimension. Also, you should use setter method for the field "previousPosition".