0% found this document useful (0 votes)
50 views4 pages

MCQ-part 2

Uploaded by

donnoorain69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

MCQ-part 2

Uploaded by

donnoorain69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Which of the following are subclasses of java.awt.Component?

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

6. How many frames are displayed?


import javax.swing.*;
public class Test {
public static void main(String[] args) {
JFrame f1 = new JFrame (“My frame”);
JFrame f2 = f1;
JFrame f3 = f2;
F1.setVisible(true);
F2.setVisible(true);
F3.setVisible(true);
}
}

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.

A. New Color(0,0,0) B. New Color(0,266,0)


C.NewColor(255,255,255)D. New Color(1,2,3)
10. Which Color is the darkest?
A.newColor(0,0,0)B.new Color(10,0,0)
C.newColor(20,0,0) D. new Color(30,0,0)

11.The method _____sets the font(Helvetica,20-point bold) in component C


a) c.setFont(new Font(“Helvetica”,BOLD,20))
b) c.setFont(new Font(“helvitica”,BOLD,20))
c) c.setFont(new Font(“Helvitica”,FontBOLD,20))
d) c.setFont(new Font(“Helvitica”,Font.BOLD,20))

12. The method __ creates a IconImage for file c:\image\us.gif.


a) New ImageIcon(“c:\image\us.gif”);
b) New Icon(“c:\image\us.gif”);
c) New ImageIcon(“c :\image\\us.gif”);
d) New ImageIcon(“c:\\image\\us.gif”);

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

17. which of these interfaces define a method actionPerformed() ?


a) ComponentListener b) ContainerListener
c) ActionListener d) InputListener

18. Which of the following methods can be used to draw the outline of a
square within a java.awt.Component object?

(A) fillRect() (B) drawLine() (C) drawRect()


(D) drawString() (E) drawPolygon()
1. (A), (B) & (C) 2.(B) & (C) 3.(A), (B), (C) & (E)
4. (B), (C) & (E) 5.(C), (D) & (E)

19. Which checkbox will be selected in the following code


( Assume with main and added to a Frame)
Frame myFrame = new Frame("Test");
CheckboxGroupcbg = new
CheckboxGroup(); Checkbox cb1 =
new Checkbox("First",true,cbg);
Checkbox cb2 = new
Checkbox("Second",true,cbg);
Checkbox cb3 = new
Checkbox("Third",false,cbg);
cbg.setSelectedCheckbox(cb3);
myFrame.add(cb1);

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

24. The method _______sets the background Color to yellow in JFrame f.


A. setbackground (Color.yellow)B.f.setBackground(Color.YELLOW)
C.f.setBackground(Color.yellow)D.setBackground(Color.YELLOW)

25. To create a JPanel of the BorderLayout ,use_____.


a) JPanel p = new JPanel()
b) JPanel p = new JPanel(BorderLayout());
c) JPanel p = new JPanel(new BorderLayout());
d) JPanel p = new JPanel().setLayout(new BorderLayout());

You might also like