See the code from the GraphicsDemo project in the lecture code repository.