Week-09 Assignment 2021 JAVA
Week-09 Assignment 2021 JAVA
PROGRAMMING IN JAVA
Assignment9
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________
QUESTION 1:
Select the correct statement(s) in the following.
Detailed Solution:
a) False: Setting JTextField property ‘setEditble=False’; it can be used as a label.
b) True: Label cannot be used to input data (it is never editble).
c) True: In a button grouped radio button, only one item can be selected similar to
JComboBox. So, they can be used interchangeably.
d) False: JPasswordField extends JTextField.
_________________________________________________________________________
QUESTION 2:
In Java AWT, TextArea and TextField are subclass of:
a. List.
b. Label.
c. TextComponent.
d. TextComponent and Label, respectively.
Correct Answer: c
Detailed Solution: TextArea and TextField are the two sub classes of TextComponent in Java
AWT.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
Analyze 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("Cancel"));
frame.add(new JButton("OK "));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
Which button will be displayed(or can be seen by user)?
a. OK
b. Cancel
c. both
d. None
Correct Answer: a
Detailed Solution:
By default, the layout of the content pane in a JFrame is BorderLayout. Button Cancel is placed
in the center of content pane, then button OK is placed in the same place. So you only can see
button OK.
______________________________________________________________________________
QUESTION 4:
In JLabel(Icon, int) method/constructor, the int argument specifies the horizontal
alignment of the label's contents within its drawing area.
Which of the following is/are not a valid constants for horizontal alignment?
a. RIGHT
b. LEADING
c. TRAILING
d. TOP
Correct Answer: d
Detailed Solution:
TOP is not a valid constant for horizontal alignment.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
____________________________________________________________________________
QUESTION 5:
Which of the following is/ are not related with keyboard event?
Correct Answer: d
Detailed Solution:
The InputEvent class is the super class of all the sub classes dealing with events from different
sources. When, we import java.awt.*, we import it automatically. No need to import it explicitly.
_____________________________________________________________________________
QUESTION 6:
Which of the following Listener(s) is/are supported by button (Swing component)?
a. ActionListener
b. ChangeListener
c. ItemListener
d. WindowListener
Detailed Solution:
_____________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 7:
Which of the following Listener Interface does not have an Adapter Class?
a. ActionListener
b. ChangeListener
c. ComponentListener
d. ItemListener
Correct Answer: a,b,d
Detailed Solution:
Only ComponentListener is having an Adapter class ComponentAdapter (among the options).
_________________________________________________________________________
QUESTION 8:
To set a FlowLayout in a panel, say jp, which of the following method(s) that you can not use?
a. jp.setLayout(new FlowLayout());
b. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
c. jp.setLayout(new FlowLayout(FlowLayout.center));
d. jp.setLayout(FlowLayout());
Correct Answer: c, d
Detailed Solution:
(c) and (d) are not valid according to the syntax.
QUESTION 9:
Which of the following is/are interface(s) in javax.swing package?
a. MenuElement
b. BoxLayout
c. JComponent
d. Scrollable
Correct Answer: a, d
Detailed Solution:
MenuElement:
Any component that can be placed into a menu should implement this interface.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Scrollable:
An interface that provides information to a scrolling container like JScrollPane.
_____________________________________________________________________________
QUESTION 10:
Which package provides many methods for graphics programming?
a. java.awt
b. java.Applet
c. java.Graphics
d. java.io
Correct Answer: a
Detailed Solution:
There is no package like java.Graphics and java.Applet. The Graphics class and other classes,
which are necessary for GUI programming is defined in java.awt package.
.
______________________________________________________________________
************END************