Rectangle on a Graphics instance?
One of hundreds of answers available with our premium content service.
A: When you have a method that takes an object as an argument, you must pass an object of the specified type in the method call. There is no Graphics method that accepts a Rectangle to draw, nor a Rectangle method that accepts a Graphics object to render to.
Since Graphics is an abstract class, you must obtain a concrete implementation. You can then use its drawRect(int x, int y, int width, int height) method to draw an outline of your rectangle, as below.
… full answer hidden
Premium members click below for full answer
How do I draw a Rectangle on a Graphics instance?