0% found this document useful (0 votes)
7 views5 pages

Week-09 Assignment 2021 JAVA

The document contains a series of multiple-choice questions related to Java programming, specifically focusing on AWT and Swing components. Each question includes a correct answer and a detailed explanation of the concepts involved. The questions cover topics such as component usage, event handling, layout management, and package functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Week-09 Assignment 2021 JAVA

The document contains a series of multiple-choice questions related to Java programming, specifically focusing on AWT and Swing components. Each question includes a correct answer and a detailed explanation of the concepts involved. The questions cover topics such as component usage, event handling, layout management, and package functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

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.

a. JTextField cannot be used as an alternative to JLabel.


b. JLabel cannot be used as an alternative to JTextField.
c. Button grouped radio button can be used as an alternative to JComboBox.
d. The class JPasswordField extends the class JLabel.

Correct Answer: b,c

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?

a. Class KeyEvent is used to notify if any key pressed occurs or not.


b. The KeyListener should be added either in init() or the main method.
c. RequestFocus should be added either in init() or the main method.
d. The class InputEvent should be imported explicitly in the program.

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

Correct Answer: a,b,c

Detailed Solution:

Except WindowListner, all other Listeners supported by button component.

_____________________________________________________________________
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).

ActionListner,changeListner,ItemListner doesn’t have an Adapter class hence a,b,d is right


answer.

_________________________________________________________________________

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.

All others are Class.

_____________________________________________________________________________

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************

You might also like