0% found this document useful (0 votes)
15 views10 pages

24a - w09 - MCQ - Final

Uploaded by

sannutha24
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)
15 views10 pages

24a - w09 - MCQ - Final

Uploaded by

sannutha24
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/ 10

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur


NOC24-CS105 (July-2024 24A)

PROGRAMMING IN JAVA
Assignment 9
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10

QUESTION 1:

Which of the following is a one‐line input field that allows the user to choose a number or an object
value from an ordered sequence?

a. JTextarea

b. Jtex ield

c. Jspinner

d. Jslider

Correct Answer:

c. Jspinner

Detailed Solu on:

A JSpinner is a one‐line input field that allows the user to choose a number or an object value from an
ordered sequence.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:

What is true about the following code.

import javax.swing.*;

public class Nptel {


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. Both “OK” and “Cancel” bu on is added, but only “Cancel” bu on is visble.

b. Only “OK” bu on is added and visible, “Cancel” bu on is not added.

c. Only “Cancel” bu on will be added and visible, “OK” bu on is not added.

d. Code throws an ERROR.

Correct Answer:

a. Both “OK” and “Cancel” bu on is added, but only “Cancel” bu on is visble.

Detailed Solu on:

By default, the layout of the content pane in a JFrame is BorderLayout. Bu on OK is placed in the center
of content pane, then bu on Cancel is placed in the same place. So you only can see bu on Cancel.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Which of the following is a container for other components and is used to build bespoke panels for
organizing and arranging components?

a. JPanel

b. JFrame

c. JCombo

d. JBox

Correct Answer:

a. JPanel

Detailed Solu on:

JPanel is a container for other components and is used to build bespoke panels for organizing and
arranging components.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

Which of the following component gives a drop‐down list of options from which to choose?

a. JPanel

b. JBu on

c. JComboBox

d. Jbox

Correct Answer:

c. JComboBox

Detailed Solu on:

JComboBox component gives a drop‐down list of op ons from which to choose.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which of the following Swing components inherently support the WindowListener interface?

a. Swing frames (JFrame)

b. Swing checkboxes (JCheckBox)

c. None of these

d. Swing combo boxes (JComboBox)

Correct Answer:

a. Swing frames (JFrame)

Detailed Solu on:

Swing frames (JFrame) and Swing dialogs (JDialog) Swing components inherently
support the WindowListener interface.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:

Which class in Swing provides a graphical way to display images, icons, or custom graphics?

a. JImage

b. JLabel

c. JImageIcon

d. JDialog

Correct Answer:

b. JLabel

Detailed Solu on:

JLabel is used to display images, icons, or custom graphics.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

What is/are the way(s) to create a Frame in Java Swing?

a. By crea ng the object of Frame class (associa on)

b. None of these

c. By impor ng a package named JFrame

d. By declaring a class with name JFrame

Correct Answer:

a. By crea ng the object of Frame class (associa on)

Detailed Solu on:

We can create a frame component by crea ng the object of Frame class (associa on) and by extending
Frame class (inheritance).
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

Which method is used to set the graphics current color to the specified color in the graphics class?

a. public abstract void setFont(Font font)

b. public abstract void setColor(Color c)

c. public abstract void drawString(String str, int x, int y)

d. None of the above

Correct Answer:

b. public abstract void setColor(Color c)

Detailed Solu on:

The method used to set the graphics current color to the specified color in the Graphics class is:
public abstract void setColor(Color c).
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

When are the keyboard events fired?

a. When the user manually calls the bu on

b. When the user right clicks the mouse

c. When the user calls the modifier

d. When the user clicks a key

Correct Answer:

d. When the user clicks a key

Detailed Solu on:

The keydown and keyup are the keyboard events are fired when the user presses or releases a key on
the keyboard. They are generated for modifier keys, func on keys, and alphanumeric keys.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which of the following function is used to specify the layout of a container.

a. UseLayeout()

b. setLayout()

c. layout()

d. DesignLayout()

Correct Answer:

b. setLayout()

Detailed Solu on:

The setLayout() func on is used to specify the layout of a container.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy