MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

COMPUTER GRAPHICS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
When an object of a class derived from JPanel needs to repaint itself, which method does it call?
A
paint(g)
B
repaint( )
C
paintComponent(g)
D
repaintComponent( )
Explanation: 

Detailed explanation-1: -Answer: The repaint() method of a component is called to notify the system that the component needs to be redrawn. It does not itself do any drawing (neither directly nor by calling the paintComponent() routine).

Detailed explanation-2: -The paint() method contains instructions for painting the specific component. The repaint() method, which can’t be overridden, is more specific: it controls the update() to paint() process. You should call this method if you want a component to repaint itself or to change its look (but not the size).

Detailed explanation-3: -The method paint() gives us access to an object of type Graphics class. Using the object of the Graphics class, we can call the drawString() method of the Graphics class to write a text message in the applet window.

Detailed explanation-4: -The Paint Method. When AWT invokes this method, the Graphics object parameter is pre-configured with the appropriate state for drawing on this particular component: The Graphics object’s color is set to the component’s foreground property. The Graphics object’s font is set to the component’s font property.

There is 1 question to complete.