MCQ-part 2
MCQ-part 2
a) Container classes
b) Swing user interface classes
c)Helper classes such as Color and font
d) Layout managers
2. What is best to describe the relationship between Jcomponent and Jbutton?
a) Association
b) Aggregation
c) Composition
d) Inheritance
3. Which component cannot be added to a container?
a) Jpanel
b) JButton
c)JFrame
d) Jcomponent
4. what layout manager should you use so that every component occupies the
same size in the container?
a) a FlowLayout
b) a GridLayout
c) a BorderLayout
d) any layout
5. Suppose a JFrame uses a GridLayout(2,2). If you add six buttons to the frame,
how many columns are displayed?
a) 1
b) 2
c) 3
d) 4
A.1 B.2
C.3 D.0
1
7. Analyse the following code:
import java.awt.*;
import javax.swing.*;
public class Test
{
public static void main(String[] args)
{
JFrame frame =new JFrame (“My Frame”);
frame.add(new JButton(“OK”));
frame.add(new JButton(“cancel”));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200,200);
frame.setVisible(true);
}
}
a) Only button OK is displayed.
b) Only button Cancel is displayed.
c)Both button OK and Button Cancel are displayed and button Ok is
displayed on the left side of button OK.
d) Both button OK and Button Cancel are displayed and button Ok is
displayed on the right side of button OK.
8. The default layout out of a JPanel is________.
A. FlowLayoutB. GridLayout
C. BorderLayoutD.None
9. ____________creates a color object.
2
13. which of these class is super class of all the events?
a)EventObject b)EventClass
c)ActionEvent d)ItemEvent
14. Which of these constant value will change when the button at the end of the
scrollbar was clicked to increase its value
a)BLOCK_DECREMENT b)BLOCK_INCREMENT
c)UNIT_DECREMENT d)BLOCK_DECREMENT
15. Which of these methods can be used to know which key is pressed?
a) getKey() b) getModifier()
c)getActionKey() d)getActionEvent()
16. which of these methods will respond when you click any button by mouse ?
a) mouseClicked() b)mouseEntered()
c) mousePressed() d) all of the mentioned
18. Which of the following methods can be used to draw the outline of a
square within a java.awt.Component object?
myFrame.add(cb2);
myFrame.add(cb3);
a) cb1 b) cb2,cb1 c) cb1,cb2,cb3 d) cb3
3
20. To use no layout manager in a container c, use _________.
A. c.setLayout() B. c.setLayout(new NullLayout())
C. c.setLayout(null) D. c.setLayout(NullLayout)
21. The method _____ gets the text (or caption ) of the button jbt.
A.jbt.text() B. jbt.getText()
C. jbt.findtext() D. jbt.retrieveText()
22. Can you use the SetToolTipText method to set a tool tip for______?
A. JLabel B. Container
C.JComponent D. JButton
23. To specify a font to be bold and italic, use the font style value__________?
(a)Font.PLAIN (b) Font.BOLD
(c) Font.ITALIC (d)Font.BOLD+Font.ITALIC