When you use a timer you need to define a class that impleme
When you use a timer, you need to define a class that implements the ____ interface.
TimerListener
TimerActionListener
ActionListener
StartTimerListener
1 points
QUESTION 3
The documentation for the JSlider class lists ____ inherited methods.
less than 5
about 25
about 250
over 2500
1 points
QUESTION 4
Which component can be added to a menu?
I JMenuBar
II JMenu
III JMenuItem
I
I and II
II and III
I, II and III
1 points
QUESTION 5
Which layout manager places objects left-to-right, and creates a new row only if when the current row cannot accommodate another object?
FlowLayout
BorderLayout
BoxLayout
GridLayout
1 points
QUESTION 6
What does the MouseAdapter class provide?
The MouseAdapter class implements all of the methods of the MouseListener interface as do nothing methods.
The MouseAdapter class allows your program to accept input from multiple mice.
The MouseAdapter class implements all of the methods of the ActionListener interface as do nothing methods.
A class can implement the MouseAdapter class to handle mouse events.
1 points
QUESTION 7
What is known for certain from this correct code excerpt?
ActionListener openListener = new FileOpenListener();
JMenuItem fileOpen = new JMenuItem(\"Open File\");
fileOpen.addActionListener(openListener);
fileOpen will open a file dialog when clicked
The fileOpen menu item will be visible
The FileOpenListener class implements the ActionListener interface
The openListener object will only listen to the fileOpen object
1 points
QUESTION 8
Given four JRadioButton objects in a ButtonGroup, how many radio buttons can be selected at the same time?
1
2
4
3
1 points
QUESTION 9
The statement that would add smallButton to the button group in the following code is _________.
JRadioButton smallButton = new JRadioButton(\"Small\");
ButtonGroup group = new ButtonGroup();
group.add(new smallButton);
group.add(smallButton);
smallButton.add();
You cannot add smallButton to the button group.
1 points
QUESTION 10
What is wrong with the following code?
class ExitListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
ActionListener exitListener = new ExitListener();
JMenu exitMenu = new JMenu(\"Exit\");
exitMenu.addActionListener(exitListener);
JMenuBar menuBar = new JMenuBar();
menuBar.add(exitMenu);
The ExitListener class is not public
You cannot attach a listener to a menu, only to a menu item
You cannot add a menu to the menu bar, only a menu item
You need to use a menu listener, not an action listener
1 points
QUESTION 11
Consider the following code snippet:
final RectangleComponent component = new RectangleComponent();
MouseListener listener = new MousePressListener();
component.addMouseListener(listener);
______________
mystery.add(component);
mystery.setSize(FRAME_WIDTH, FRAME_HEIGHT);
mystery.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mystery.setVisible(true);
Which of the following statements completes this code?
JPanel mystery = new JPanel();
JComponent mystery = new JComponent();
Frame mystery = new Frame();
JFrame mystery = new JFrame();
1 points
QUESTION 12
What type of object can be added into a JComboBox by the addItem method?
Object
String
JRadioButton
any non-primitive type
1 points
QUESTION 13
Consider the code snippet below:
public class RectangleComponent extends JComponent
{
private static final int RECTANGLE_WIDTH = 20;
private static final int RECTANGLE_HEIGHT = 30;
private int xLeft;
private int yTop;
public RectangleComponent()
{
xLeft = 0;
yTop = 0;
}
public void paintComponent(Graphics g)
{
g.fillRect(xLeft, yTop, RECTANGLE_WIDTH, RECTANGLE_HEIGHT);
}
public void moveRectangleBy(int dx, int dy)
{
xLeft = xLeft + dx;
yTop = yTop + dy;
repaint();
}
}
Which statement(s) causes the rectangle to appear at an updated location?
repaint();
public void moveRectangleBy(int dx, int dy);
xLeft = xLeft + dx;
yTop = yTop + dy;
xLeft = 0;
yTop = 0;
1 points
QUESTION 14
When a menu item is selected, what type of event does it send?
ActionEvent
ChangeEvent
ItemEvent
SelectionEvent
1 points
QUESTION 15
To create a _____ layout, you supply the number of rows and columns in the constructor, then add the components, row by row, left to right.
border
grid
grid bag
boxed
1 points
QUESTION 16
Consider the following code snippet:
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println(event);
}
}
Timer t = new Timer(interval, listener);
t.start();
What is wrong with this code?
The Timer object should be declared before the MyListener class.
The listener must be declared as new MyListener().
The Timer object must be declared as final.
The word listener should be change to MyListener.
1 points
QUESTION 17
Which of the following methods returns the object that was selected in the JComboBox?
getSelected
getItem
getChoice
getSelectedItem
1 points
QUESTION 18
The code below will not compile successfully unless the argument to the makeMenuItem method is final. Why not?
public JMenuItem makeMenuItem(final String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel);
class MyMenuListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
doSomethingElse();
System.out.println(menuLabel);
}
}
mi.addActionListener(new MyMenuListener());
return mi;
}
JMenuItem labels must be final
This prevents the menuLabel argument from being modified
Because a local variable is being accessed from an inner classes
Because the String class is final
1 points
QUESTION 19
You wish to detect when the mouse is moved into a graphical component. Which methods of the associated MouseListener interface will provide this information?
mouseMoved
mouseEntered
mouseOver
mouseIncoming
1 points
QUESTION 20
The event that is generated by a slider when its value changes is of type _____.
ActionEvent
ChangeEvent
ItemEvent
MouseEvent
| TimerListener | ||
| TimerActionListener | ||
| ActionListener | ||
| StartTimerListener |
Solution
[2] ActionListener interface
[3] about 250 inherited methods
[4] all are component to a menu.
[5] FlowLayout
[6] The MouseAdapter class implements all of the methods of the MouseListener interface as do nothing methods
[7] The FileOpenListener class implements the ActionListener interface
[8] 1 button at a time
[9] group.add(smallButton)
[10] You cannot attach a listener to a menu, only to a menu item
[11] JFrame mystery = new JFrame();
[12] any non-primitive type
[13] xLeft = xLeft + dx;
yTop = yTop + dy;
[14] ActionEvent
[15] grid
[16] The listener must be declared as new MyListener().
[17] getSelectedItem
[18] Because a local variable is being accessed from an inner classes
[19] mouseEntered
[20] ChangeEvent






