Which of the following methods are invoked by the AWT to support paint and repaint operations?
- Apaint( )
- Brepaint( )
- Cdraw( )
- Dredraw( )
The AWT system itself calls paint() when a component must be drawn; programs call repaint() to request it.
MCQs, short and long questions from lecture 18.Lecture 18 ki MCQs, short aur long sawal.
6 MCQs · 9 short · 1 long question · 6 MCQs from past papers6 MCQs · 9 short · 1 long sawal · 6 MCQs past papers se
Which of the following methods are invoked by the AWT to support paint and repaint operations?
The AWT system itself calls paint() when a component must be drawn; programs call repaint() to request it.
Which of the following are passed as an argument to the paint ( ) method?
paint(Graphics g) receives a Graphics object used for drawing.
The code below draws a line. What color is the line? g.setColor(Color.red.green.yellow.red); g.drawLine(0, 0, 100,100);
Each static field access through an instance just reads the named constant, so the last one, Color.red, is used.
Which of the following statement is true regarding paintComponent() method?
By default paintComponent paints the background, then the custom drawing is done.
Which of the following object is passed as an argument to paintComponent() method?
paintComponent(Graphics g) receives a Graphics object.
Which of the following method of Graphics object is used to draw rectangle?
The Graphics method is drawRect(x, y, width, height).
No MCQs match this filter.Is filter mein koi MCQ nahi.
Why is direct call of paint() method not recommended?
Painting is controlled by the system: it calls paint() (through update/paintComponent) when needed and supplies the correct Graphics object. If the program calls paint() directly it must get a Graphics object itself, may paint at the wrong time, outside the event thread or in conflict with system repainting, and Swing double buffering and the painting of borders and children may be skipped. Instead the program should call repaint(), which asks the system to schedule a proper repaint as soon as possible.
3 Paint methods which are used to paint swing component
paintComponent(Graphics g), paintBorder(Graphics g) and paintChildren(Graphics g), called in that order by paint().
Why we use paintChildern( ) method?
paintChildren(Graphics g) is called by paint() to tell all components contained in this component to paint themselves. It is part of Swing’s painting process and normally should not be overridden or called directly.
Write any two steps of painting strategy.
1. Subclass JPanel (or another JComponent). 2. Override paintComponent(Graphics g), call super.paintComponent(g) and draw with the Graphics object. (To show changes later, call repaint() instead of calling paint methods directly.)
Name three paint () methods which are used to paint Swing Component.
protected void paintComponent(Graphics g) protected void paintBorder(Graphics g) protected void paintChildren(Graphics g)
Why is directly paintComponent () method not recommended?
Painting is managed by the system. If paintComponent() (or paint()) is called directly, it may run at a wrong time, e.g. before the component is visible or when no valid Graphics object is available. Instead repaint() should be called, which asks the system to repaint the component at a suitable time.
Name component subclasses that support painting
In AWT: Canvas, Panel, Frame and Applet (overriding paint()). In Swing, any JComponent such as JPanel (overriding paintComponent()).
Which Component subclasses are used for paint
Canvas, Panel, Frame and Applet in AWT; in Swing, JComponent subclasses such as JPanel.
What is the difference between the paint() and repaint() methods?
paint() (paintComponent() in Swing) contains the actual drawing code; it is overridden to change how a component looks and is called by the system. repaint() is called by the program to request that the component be redrawn; the system then calls update()/paint() as soon as it can. Programs should call repaint(), not paint() directly.
What will happen if an image drawn out of the window coordinates?
Nothing fails: drawing is clipped to the component’s visible area. The part of the image that lies outside the window coordinates is simply not shown (and is not drawn at all if it is completely outside); no error or exception occurs. It becomes visible only if the window is enlarged or the image is moved inside the drawable area.