0% found this document useful (0 votes)
28 views13 pages

AJP

Uploaded by

Sanskar Rangole
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)
28 views13 pages

AJP

Uploaded by

Sanskar Rangole
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/ 13

What does GUI stand for?

a) Graphical User Interface


b) General User Interface
c) Graphics Utility Interface
d) Graphical Utility Interface
Answer: a) Graphical User Interface

A ____ is a passive AWT control that does not generate any event.
a) Button
b) Choice
c) Panel
d) Label
Answer: d) Label
Which package contains the Java Swing classes?
a) java.lang
b) java.io
c) java.util
d) javax.swing
Answer: d) javax.swing

Which AWT component is used to create a text control that can display multiple lines of text?
a) TextArea
b) TextPane
c) TextField
d) MultiLineText
Answer: a) TextAreaWhich class is used as the base class for all Swing components?
a) Component
b) Container
c) JPanel
d) JFrame
Answer: a) Component

TabbedPane class is present in which package?


a) java.awt
b) java.util
c) javax.swing
d) java.awt.event
Answer: c) javax.swing

Which layout manager is used by default for JFrame?


a) BorderLayout
b) FlowLayout
c) GridLayout
d) CardLayout
Answer: a) BorderLayout

Which class is used to create a button in Java Swing?


a) JButton
b) JLabel
c) JRadioButton
d) JTextArea
Answer: a) JButton
In Swing, the content pane can be obtained via method ________
a) getContentPane
b) getContainer
c) getWindow
d) getFrameWindow
Answer: a) getContentPane
Which event listener interface is used for handling button click events?
a) ActionListener
b) ItemListener
c) MouseListener
d) KeyListener
Answer: a) ActionListener

What is the purpose of the setVisible() method in JFrame?


a) To set the size of the frame
b) To set the title of the frame
c) To make the frame visible on the screen
d) To close the frame
Answer: c) To make the frame visible on the screen

The ___________ interface is used to handle button events:


a) ContainerListener
b) ItemListener
c) ActionListener
d) WindowListener
Answer: c) ActionListener
The Delegation Event Model is based on the concept of ____________
a) Source
b) Listener
c) Both a & b
d) None of these
Answer: c) Both a & b
What is the purpose of the setLayout() method in Java Swing?
a) To set the background color of a component
b) To set the size of a component
c) To set the layout manager for a container
d) To set the font style for a component
Answer: c) To set the layout manager for a container

Which layout manager is used to arrange components in a grid-like structure?


a) BorderLayout
b) FlowLayout
c) GridLayout
d) GridBagLayout
Answer: c) GridLayout

What is the purpose of the repaint() method in Java Swing?


a) To change the background color of a component
b) To add a new component to a container
c) To revalidate the layout of a container
d) To redraw a component on the screen
Answer: d) To redraw a component on the screen
Which class is used to display text in Java Swing?
a) JTextField
b) JTextArea
c) JLabel
d) JList
Answer: c) JLabel

Which event listener interface is used for handling keyboard events?


a) ActionListener
b) ItemListener
c) MouseListener
d) KeyListener
Answer: d) KeyListener

What is the purpose of the setResizable() method in JFrame?


a) To set the size of the frame
b) To set the title of the frame
c) To make the frame resizable or non-resizable
d) To close the frame
Answer: c) To make the frame resizable or non-resizable
Which components are used in the following?
a) Checkbox, Applet, Label
b) Checklist, Frame, Label
c) List, Applet, TextField
d) Combobox, Applet, Label
Answer: d) Combobox, Applet, Label
Choose the missing statement in the following code from the given options:

java
Copy code
import java.awt.*;
import java.applet.*;
public class Ellipses extends Applet {
{
g.drawOval(10, 10, 50, 50);
g.fillOval(100, 10, 75, 50);
g.drawOval(190, 10, 90, 30);
g.fillOval(70, 90, 140, 100);
}
}
a) public void init()
b) public void paint(Graphics g)
c) public static void main(String args[])
d) public void paint(String s)
Answer: b) public void paint(Graphics g)
For the below code, how is a JTable object created?

java
Copy code
String[] colHeads = { "Name", "Extension", "ID#" };
Object[][] data = {{"Gail", "4567", "865"},{"Ken", "7566", "555"}};
a) Table jt = new JTable(colHeads);
b) Table jt = new JTable(data);
c) Table jt = new JTable(data, colHeads);
d) All of the above
Answer: c) Table jt = new JTable(data, colHeads)

Which Node is missing in the color node code?

java
Copy code
DefaultMutableTreeNode style = new DefaultMutableTreeNode("Style");
DefaultMutableTreeNode color = new DefaultMutableTreeNode("color");
style.add(color);
DefaultMutableTreeNode red = new DefaultMutableTreeNode("red");
DefaultMutableTreeNode blue = new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black = new DefaultMutableTreeNode("black");
DefaultMutableTreeNode green = new DefaultMutableTreeNode("green");
color.add(red);
color.add(black);
color.add(green);
JTree jt = new JTree(style);
a) color.add(red);
b) color.add(blue);
c) color.add(black);
d) color.add(green);
Answer: b) color.add(blue)

Fill in the missing elements in the following sequence: a) ActionListener, addActionListener,


actionPerformed, ActionEvent
b) ActionListener, addMouseListener, actionPerformed, MouseEvent
c) ActionListener, addActionListener, actionPerformed
d) KeyListener, addKeyListener, actionPerformed, KeyEvent
Answer: a) ActionListener, addActionListener, actionPerformed, ActionEvent

Fill up the correct listener name and event name in the code:

java
Copy code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="SimpleKeyDemo" width=300 height=100> </applet> */
public class SimpleKeyDemo extends Applet implements _____________ {
String msg = "";
int X = 10, Y = 20;
public void init() {
addKeyListener(this);
requestFocus();
}
public void keyPressed( _________ ke) {
showStatus("Key Down");
}
public void keyReleased( _________ ke) {
showStatus("Key Up");
}
public void keyTyped( ____________ ke) {
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g) {
g.drawString(msg, X, Y);
}
}
a) KeyListener, KeyEvent
b) MouseListener, MouseEvent
c) ActionListener, ActionEvent
d) TextListener, TextEvent
Answer: a) KeyListener, KeyEvent

From the given list, which is not a method of MouseListener?


a) mouseClicked
b) mouseEntered
c) mouseExited
d) mouseDragged
Answer: d) mouseDragged()

Which of the following Swing components can display an image?


a) JButton
b) JLabel
c) JTextArea
d) JTable
Answer: b) JLabel

What does AWT stand for?


a) Abstract Window Technology
b) Abstract Window Toolkit
c) Advanced Window Toolkit
d) Advanced Window Technology
Answer: b) Abstract Window Toolkit

In Java, a component is an object that is stored in which of the following?


a) Layout
b) Event
c) Container
d) GUI
Answer: c) container
Which class is the parent class of all AWT components?
a) java.awt.Object
b) java.awt.Component
c) java.awt.Container
d) java.awt.LayoutManager
Answer: b) java.awt.Component

True or False: The Container class can contain other components like buttons, text fields, and
panels.
a) TRUE
b) FALSE
Answer: a) TRUE

How many constructors are available in the TextField class?


a) 0
b) 1
c) 2
d) 5
Answer: d) 5

What is used to arrange the components inside the container?


a) Border
b) Color
c) Font
d) Layout manager
Answer: d) layout manager
Which method can be used to set or change the text in a JLabel?
a) setLabel(String str)
b) setText(String str)
c) setLabelText(String str)
d) setTitle(String str)
Answer: b) setText(String str)

Which interface defines the actionPerformed() method?


a) java.awt.event.WindowListener interface
b) java.awt.event.MouseListener interface
c) java.awt.event.KeyListener interface
d) java.awt.event.ActionListener interface
Answer: d) java.awt.event.ActionListener interface

Which method in Java Swing can be used to set the text color of a component?
a) setBackground(Color clr)
b) setForeground(Color clr)
c) setColor(Color clr)
d) setTextColor(Color clr)
Answer: b) setForeground(Color clr)

True or False: The java.awt package contains only the core classes required for event handling.
a) TRUE
b) FALSE
Answer: b) FALSE
Which of the following methods can be used to add a MouseMotionListener to a component?
a) addMouseListener()
b) addMouseMotionListener()
c) addMouseMoveListener()
d) addMouseDragListener()
Answer: b) addMouseMotionListener()

Which of the following statements is true about an event listener?


a) A listener is an object that receives notifications about events only in applets
b) A listener is an object that is notified when an event occurs
c) A listener is an object that is not concerned with events
d) A listener is an object that generates events
Answer: b) A listener is an object that is notified when an event occurs

Which of the following packages contains event handling classes in Java?


a) java.io
b) java.lang
c) java.util
d) java.awt.event
Answer: d) java.awt.event
Which method of ActionEvent class is used to return the identification number of the event?
a) getID()
b) getAction()
c) getSource()
d) getTarget()
Answer: a) getID()

You might also like