Question 1 (5 points) The method __________ sets the background color to yellow
ID: 3817265 • Letter: Q
Question
Question 1 (5 points)
The method __________ sets the background color to yellow in JFrame frame.
Question 1 options:
setBackground(Color.YELLOW)
frame.setBackGround(Color.yellow)
frame.setBackground(Color.YELLOW)
setBackground(Color.yellow)
Save
Question 2 (5 points)
What layout manager should you use so that every component occupies the same size in the container?
Question 2 options:
BorderLayout
GridLayout
FlowLayout
any layout
Save
Question 3 (5 points)
Which of the following statements is for terminating the program when closing the frame?
Question 3 options:
frame.setDefaultCloseOperation(null)
frame.setDefaultCloseOperation(JFrame.STOP_ON_CLOSE)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE)
Save
Question 4 (5 points)
Which of the following statements about containers is correct?
Question 4 options:
A frame can be placed inside a panel
A panel can be placed inside a panel
Both frames and panels can be placed inside a panel
A frame can be placed inside a frame
Save
Question 5 (5 points)
Which method call puts the string "Result" into the TextField named result?
Question 5 options:
result.setText("Result")
result.text("Result")
result.findText()
result.newText("Result")
Save
Question 6 (5 points)
How many items can be added into a JComboBox object?
Question 6 options:
0
2
Unlimited
1
Save
Question 7 (5 points)
What kind of object is used group radio buttons?
Question 7 options:
JButtonGroup
Group
ButtonGroup
ContainerGroup
Save
Question 8 (5 points)
Which of the following method calls is used to prevent the user from modifying a text field tf?
Question 8 options:
tf.setChangable(false);
tf.preventMdification()
tf.setUneditable()
tf.setEditable(false);
Save
Question 9 (5 points)
When you want to allow the user to select only one of several choices, which you use?
Question 9 options:
Radio buttons
Ordinary buttons
Text fields
Check boxes
Save
Question 10 (5 points)
What is the benefit of using layout managers?
Question 10 options:
It reduces the amount of code needed
It defines how components of a window should be arranged when it is resized
It makes the program run much faster
It reduces the amount of memory necessary to store the window components
Save
Question 11 (5 points)
Which of the following true about source and listener objects?
Question 11 options:
Both objects must be of the same type
They must always be different objects
They can be the same object
The objects must always be of different types
Save
Question 12 (5 points)
Which of the following statements is incorrect?
Question 12 options:
A listener may listen for multiple sources
The listener object must be registered by the source object
A source object can only have one listener object
The listener object's class must implement the corresponding event-listener interface
Save
Question 13 (5 points)
Given the code below, indicate which statement describes its behavior.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Quiz3A extends JFrame implements ActionListener
{
public Quiz3A()
{
JButton okButton = new JButton("OK");
add(okButton);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("The OK button is clicked");
}
public static void main(String[] args)
{
JFrame frame = new Quiz3A();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Question 13 options:
The program has a compilation error because no listeners are registered for okButton
The message The OK button is clicked is displayed when you click the OK button
The actionPerformed method is not executed when you click the OK button, because no instance of Quiz3A is registered with okButton
The program has a runtime error because no listeners are registered with okButton
Save
Question 14 (5 points)
The listener for an button event is an instance of ________.
Question 14 options:
ItemListener
KeyListener
MouseListener
ActionListener
Save
Question 15 (5 points)
Which of the following statements registers a panel object aPanel as a listener for a button variable aButton?
Question 15 options:
aButton.addActionEventListener(aPanel);
aButton.addActionListener(aPanel);
addActionListener(aPanel);
aPanel.addEventListener(aPanel);
Save
Question 16 (5 points)
In the program below, which object is listening for the events of okButton?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Quiz3B extends JFrame implements ActionListener
{
private JButton okButton = new JButton("OK");
public Quiz3B()
{
add(okButton);
okButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("The OK button is clicked");
}
public static void main(String[] args)
{
JFrame frame = new Quiz3B();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Question 16 options:
An anonymous object
okButton
JButton
frame
Save
Question 17 (5 points)
What is the benefit of using adapter classes rather than listeners interfaces?
Question 17 options:
It makes the response time for responding to events much quicker
It makes it possible to respond to several events at the same time
It enables multiple inheritance of classes
It makes it unnecessary to implement unused event handling methods
Save
Question 18 (5 points)
In the program below, which object is listening for the events of okButton?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Quiz3C extends JFrame
{
private JButton okButton = new JButton("OK");
public Quiz3C()
{
add(okButton);
okButton.addActionListener(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent ae)
{
System.out.println("The OK button is clicked");
}
});
}
public static void main(String[] args)
{
JFrame frame = new Quiz3C();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Question 18 options:
frame
An anonymous object
okButton
JButton
Save
Question 19 (5 points)
Which of the following will occur if you fail to register an object as a listener for the click events of a button?
Question 19 options:
A compilation error will occur
Nothing will happen when the button is clicked
A class cast exception will be thrown at run-time
The containing frame will be considered as the default listener
Save
Question 20 (5 points)
When a mouse event is generated how is the location of the click point determined?
Question 20 options:
It is extracted from the mouse event that is passed to the event handler
The event handler must generate a secondary event to obtain the location
It is automatically saved as an instance variable in the object of which the mouse was clicked
It is obtained by calling a method of the mouse object
setBackground(Color.YELLOW)
frame.setBackGround(Color.yellow)
frame.setBackground(Color.YELLOW)
setBackground(Color.yellow)
Explanation / Answer
1 Ans:- C
frame.setBackground(Color.YELLOW)
Retrieve the content pane for the frame and use the setBackground() method inherited from Component to change the color.
Example:
2 Ans:- B
GridLayOut
A GridLayout Manager places the components in a rectangular grid. Each component’s position is identified by a column and row. All the cells in the grid have same size and width. Each component is stretched to the cell size. So a GridLayout ignores the Component’s preferred size.
3 Ans:- C
Answer is frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
4 Ans:- The correct answer is B
A panel can be placed inside a panel
We cannot Put a JFrame inside a JFrame. For this purpose we have to Use JPanels.
Like below , you can add two panels to a JPanel.
5 Ans : A
result.setText("Result")
6 ANs:- C
Unlimited.
We can add unlimited items to a JComponent Object.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.