Question: Consider the code snippet below: public class RectangleComponent extends JComponent { private static final int RECTANGLE_WIDTH = 20; private static final int RECTANGLE_HEIGHT = 30;
Consider the code snippet below:
public class RectangleComponent extends JComponent { private static final int RECTANGLE_WIDTH = 20; private static final int RECTANGLE_HEIGHT = 30; private int xLeft; private int yTop; public RectangleComponent() { xLeft = 0; yTop = 0; } public void paintComponent(Graphics g) { g.fillRect(xLeft, yTop, RECTANGLE_WIDTH, RECTANGLE_HEIGHT); } public void moveRectangleBy(int dx, int dy) { xLeft = xLeft + dx; yTop = yTop + dy; getGraphics().setColor(Color.green); repaint(); } } Which color will be used to fill a rectangle in paintComponent?
| green |
| the system's default color |
| white |
| it is impossible to specify |
Flag this Question
Question 2 0.1 pts
If you need force the screen to be updated, you should call the method ____.
draw |
update |
paintComponent |
repaint |
Flag this Question
Question 3 0.1 pts
Complete the following statement to construct a rectangle.
Graphics g; g.____________________ (x, y, width, height);
drawRect |
drawOval |
fillCircle |
DrawOval |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
