Question
QUESTION 1 Complete the following statement to construct a circle. Graphics g; g.____________________(x, y, width, height); drawCircle drawOval fillCircle DrawOval 2 points QUESTION 2 The
QUESTION 1
Complete the following statement to construct a circle. Graphics g; g.____________________(x, y, width, height);
drawCircle | ||
drawOval | ||
fillCircle | ||
DrawOval |
2 points
QUESTION 2
The methods of a/an ____ describe the actions to be taken when an event occurs.
event source | ||
event listener | ||
event interface | ||
action source |
2 points
QUESTION 3
Which of the following statements creates a button with "Calculate" as its label?
Button JButton = new Button("Calculate") | ||
button = new Button(JButton, "Calculate") | ||
Button = new JButton("Calculate") | ||
JButton button = new JButton("Calculate") |
2 points
QUESTION 4
Event listeners are often installed as ____ classes so that they can have access to the surrounding fields, methods, and final variables.
Inner | ||
Interface | ||
Abstract | ||
Helper |
2 points
QUESTION 5
Which of the following statements will compile without error?
public interface AccountListener() { void actionPerformed(AccountEvent event); } | ||
public interface AccountListener() { void actionPerformed(AccountEvent); } | ||
public interface AccountListener { void actionPerformed(AccountEvent event); } | ||
public abstract AccountListener { void actionPerformed(AccountEvent event); } |
2 points
QUESTION 6
When an event occurs, the event source notifies all associated ____.
components | ||
panels | ||
interfaces | ||
event listeners |
2 points
QUESTION 7
Complete this code fragment to ensure that the application exits properly when the user closes the frame: JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JFrame.setCloseOperation(JFrame.EXIT); | ||
frame.setCloseOperation(JFrame.EXIT); |
2 points
QUESTION 8
To draw an ellipse, you must include which of the following import statements?
import java.awt.Graphics; | ||
import javax.awt; | ||
import javax.swing.JPanel; | ||
import java.awt.Ellipse; |
2 points
QUESTION 9
An inner class can access local variables from the enclosing method only if they are declared as ____.
private | ||
public | ||
static | ||
final |
2 points
QUESTION 10
Which of the following statements about an inner class is true?
An inner class may not be declared within a method of the enclosing scope. | ||
An inner class may only be declared within a method of the enclosing scope. | ||
An inner class can access variables from the enclosing scope only if they are passed as constructor or method parameters. | ||
The methods of an inner class can access variables declared in the enclosing scope. |
2 points
QUESTION 11
Consider the following code snippet: JFrame frame = new JFrame(); JPanel panel = new JPanel(); Which statement would add the panel to the frame?
frame.add(panel); | ||
frame.add(JPanel panel); | ||
frame.addComponent(panel); | ||
frame.addComponent(JPanel panel); |
2 points
QUESTION 12
Consider the following code snippet: public static void main(String[] args) { Order myOrder = new Order(); JButton button = new JButton("Calculate"); JLabel label = new JLabel("Total amount due"); . . . class MyListener implements ActionListener { public void actionPerformed(ActionEvent event) { label.setText("Total amount due " + myOrder.getAmountDue()); } } } What is wrong with this code?
label must be declared as final. | ||
myOrder must be declared as final. | ||
label and myOrder must be declared as final. | ||
label and button must be declared as final. |
2 points
QUESTION 13
What happens if a text field's width is set to 10 characters and the user types more characters into it?
The user interface automatically widens the field's width. | ||
An InputMismatchException is thrown. | ||
The earlier characters are deleted and only the last ten are shown and entered. | ||
The characters are entered but only those that fit into the width are shown. |
2 points
QUESTION 14
How do you specify what the program should do when the user clicks a button?
Specify the actions to take in a class that implements the ButtonListener interface. | ||
Specify the actions to take in a class that implements the ButtonEvent interface . | ||
Specify the actions to take in a class that implements the ActionListener interface. | ||
Specify the actions to take in a class that implements the EventListener interface. |
2 points
QUESTION 15
Which of the following statements about events and graphical user interface programs is true?
Your program must indicate the specific types of events to which it wishes to respond. | ||
Your program will automatically receive notifications about all events that have occurred. | ||
Your program must respond to notifications of all types of events that are sent to it while it is running. | ||
Your program must override the default methods to handle events. 11)____ are generated when the user presses a key, clicks a button, or selects a menu item. a) Listeners b) Interfaces. *c) Events. d) Errors. |
2 points
QUESTION 16
What's the difference between a text field and a text area?
A text field is used for input only and a text area is used for output only. | ||
A text field can be edited by the user but a text area cannot. | ||
A text area can have scroll bars but a text field cannot. | ||
A text field is for a single line of text and a text area is for multiple lines of text. |
2 points
QUESTION 17
Based on the following statement, which of the following statements sets the title of the frame: JFrame frame = new JFrame();
frame.title = "An Empty Frame"; | ||
frame.setTitle(JFrame.EMPTY); | ||
frame.addTitle("An Empty Frame"); | ||
frame.setTitle("An Empty Frame"); |
2 points
QUESTION 18
Which container is used to group multiple user-interface components together?
text area | ||
table | ||
panel | ||
rectangle |
2 points
QUESTION 19
If a text field holds an integer, what expression do you use to read its contents?
(int) textField.getText() | ||
(Integer) textField.getText() | ||
Integer.parseInt(textField.getText()) | ||
Int.parseInteger(textField.getText()) |
2 points
QUESTION 20
To build a user interface that contains multiple graphical components, the components ____.
Must be added directly to a frame component. | ||
Must each be added to a separate panel. | ||
Must be added to a panel that is contained within a frame. | ||
Must be added to a frame that is contained within a panel. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started