Develop a routine. Not paying attention is, really, a bad habit. Just like any other habit, you can break it by replacing it with other habits. Try to create a system where you focus in class, making that time just for school and learning, but give yourself times of relief where you can have lots of fun. By teaching your brain what time of the day is for what by sticking to a routine, you can train your brain to pay attention.