Deck 12: A First Look at GUI Applications
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 12: A First Look at GUI Applications
1
When using the BorderLayout manager, how many components can each region hold?
A) 1
B) 2
C) 5
D) No limit
A) 1
B) 2
C) 5
D) No limit
A
2
The minimize button, maximize button, and close button on a window are sometimes referred to as:
A) operations buttons
B) sizing buttons
C) decorations
D) display buttons
A) operations buttons
B) sizing buttons
C) decorations
D) display buttons
C
3
This is an action that takes place in an application, such as the clicking of a button.
A) instance
B) effect
C) case
D) event
A) instance
B) effect
C) case
D) event
D
4
These components have a consistent look and predictable behavior on any operating system.
A) AWT
B) GUI
C) Swing
D) Peer classes
A) AWT
B) GUI
C) Swing
D) Peer classes
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
5
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
A) panel.setLayout(new (GridLayout(2,3));
B) panel.addLayout(new (GridLayout(2,3));
C) panel.GridLayout(2,3);
D) panel.attachLayout(GridLayout(2,3));
A) panel.setLayout(new (GridLayout(2,3));
B) panel.addLayout(new (GridLayout(2,3));
C) panel.GridLayout(2,3);
D) panel.attachLayout(GridLayout(2,3));
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
In a Swing application, you create a frame object from the:
A) Jlabel class
B) JFrame class
C) Jpanel class
D) AbstractButton class
A) Jlabel class
B) JFrame class
C) Jpanel class
D) AbstractButton class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
Which one of the following GUI components is considered to be a container?
A) Frame
B) Label
C) Slider
D) Button
A) Frame
B) Label
C) Slider
D) Button
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
________ is a library of classes that do not replace ________, but provide an improved alternative for creating GUI applications.
A) AWT, Swing
B) Swing, AWT
C) JFC, AWT
D) JFC, Swing
A) AWT, Swing
B) Swing, AWT
C) JFC, AWT
D) JFC, Swing
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
This is commonly used to hold and organize collections of related components:
A) list
B) panel
C) frame
D) label
A) list
B) panel
C) frame
D) label
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
In Swing, labels are created with this class:
A) JFCLabel
B) AWTLabel
C) JLabel
D) SwingLabel
A) JFCLabel
B) AWTLabel
C) JLabel
D) SwingLabel
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
One of the small dots that make up a screen display is known as what?
A) point
B) color
C) pixel
D) texture
A) point
B) color
C) pixel
D) texture
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
12
To use the ActionListener interface, as well as other event listener interfaces, you must have the following import statement in your code:
A) import java.swing;
B) import java.awt;
C) import java.awt.*;
D) import java.awt.event.*;
A) import java.swing;
B) import java.awt;
C) import java.awt.*;
D) import java.awt.event.*;
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation() method.
A) END_ON_CLOSE
B) JFrame.END_ON_CLOSE
C) JFrame.EXIT_ON_CLOSE
D) JFrame.CLOSE_NOT_HIDE
A) END_ON_CLOSE
B) JFrame.END_ON_CLOSE
C) JFrame.EXIT_ON_CLOSE
D) JFrame.CLOSE_NOT_HIDE
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
In GUI terminology, a container that can be displayed as a window is known as a:
A) message dialog
B) buffer
C) Swing package
D) frame
A) message dialog
B) buffer
C) Swing package
D) frame
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
To use the Color class, which is used to set the foreground and background of various objects, use the following import statement:
A) import java.swing;
B) import java.awt;
C) import java.awt.*;
D) import java.awt.event.*;
A) import java.swing;
B) import java.awt;
C) import java.awt.*;
D) import java.awt.event.*;
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
This layout manager arranges components in regions named North, South, East, West, and Center.
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
17
Because these components rely on the appearance and behavior of the underlying operating system components, there is little that can be done by the programmer to change their properties.
A) Swing
B) AWT
C) Container
D) JFC
A) Swing
B) AWT
C) Container
D) JFC
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
Programs that operate in a GUI environment must be:
A) event driven
B) in color
C) dialog boxes
D) layout managers
A) event driven
B) in color
C) dialog boxes
D) layout managers
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
When you write an action listener class for a JButton component, it must:
A) have a method named buttonClicked
B) implement the ActionLIstener interface
C) have a method named actionPerformed which must take an argument of the ActionEvent type
D) both B and C
A) have a method named buttonClicked
B) implement the ActionLIstener interface
C) have a method named actionPerformed which must take an argument of the ActionEvent type
D) both B and C
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
This layout manager arranges components in rows.
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
JFC stands for:
A) Java Fundamental Classes
B) Java Foundation Classes
C) Java Fundamental Core
D) Java Frame Class
A) Java Fundamental Classes
B) Java Foundation Classes
C) Java Fundamental Core
D) Java Frame Class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
22
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is hidden, but not closed.
A) HIDE_ON_CLOSE
B) JFrame. HIDE_ON_CLOSE
C) JFrame.EXIT_ON_CLOSE
D) JFrame.HIDE_NOT_CLOSE
A) HIDE_ON_CLOSE
B) JFrame. HIDE_ON_CLOSE
C) JFrame.EXIT_ON_CLOSE
D) JFrame.HIDE_NOT_CLOSE
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is NOT a rule for the FlowLayout manager?
A) Multiple components can be added to a container that uses a FlowLayout manager.
B) New components will be added in a row from left to right.
C) When there is no more room in a row, additional components are put on the next row.
D) All of these are rules for the FlowLayout manager.
A) Multiple components can be added to a container that uses a FlowLayout manager.
B) New components will be added in a row from left to right.
C) When there is no more room in a row, additional components are put on the next row.
D) All of these are rules for the FlowLayout manager.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
AWT components are commonly called ________ components because they are coupled with their underlying peer classes.
A) lightweight
B) featherweight
C) middleweight
D) heavyweight
A) lightweight
B) featherweight
C) middleweight
D) heavyweight
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
25
What does the following statement do?
AddButton.addActionListener(new AddButtonListener());
A) Creates an AddButtonListener object
B) Registers the addButton object as an ActionListener with the AddButtonListener object
C) Creates an AddButtonListener object and registers the AddButtonListener object with the addButton
D) Nothing, the statement is invalid.
AddButton.addActionListener(new AddButtonListener());
A) Creates an AddButtonListener object
B) Registers the addButton object as an ActionListener with the AddButtonListener object
C) Creates an AddButtonListener object and registers the AddButtonListener object with the addButton
D) Nothing, the statement is invalid.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
The GridLayout manager limits each cell to only one component. To put two or more components in a cell, do this:
A) Resize the cells so they can hold more
B) You can nest panels inside the cells, and add other components to the panels
C) The statement is False. The GridLayout manager does not have this restriction
D) Resize the components to fit in the cell
A) Resize the cells so they can hold more
B) You can nest panels inside the cells, and add other components to the panels
C) The statement is False. The GridLayout manager does not have this restriction
D) Resize the components to fit in the cell
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
Assume that radio references a JRadioButton object. To click the radio button in code, use the following statement:
A) radio.Click();
B) Click(radio);
C) Click(radio, true);
D) radio.doClick();
A) radio.Click();
B) Click(radio);
C) Click(radio, true);
D) radio.doClick();
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
What will be the result of executing the following statement?
Panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
A) The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
B) The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
C) The JPanel referenced by panel will have a blue line border that is 5 characters thick.
D) The JPanel referenced by panel will have a blue line border that is 5 inches thick.
Panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
A) The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
B) The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
C) The JPanel referenced by panel will have a blue line border that is 5 characters thick.
D) The JPanel referenced by panel will have a blue line border that is 5 inches thick.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following statements is NOT true?
A) Radio buttons are round and check boxes are square.
B) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not.
C) Radio buttons and check boxes both implement the ActionListener interface.
D) They are all true.
A) Radio buttons are round and check boxes are square.
B) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not.
C) Radio buttons and check boxes both implement the ActionListener interface.
D) They are all true.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
30
This layout manager arranges components in five regions.
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
A) GridLayout
B) BorderLayout
C) FlowLayout
D) RegionLayout
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing, and closing the window.
A) Pane
B) Container
C) Frame
D) Dialog box
A) Pane
B) Container
C) Frame
D) Dialog box
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
32
How many radio buttons can be selected at the same time as the result of the following code?
Hours = new JRadioButton("Hours");
Minutes = new JRadioButton("Minutes");
Seconds = new JRadioButton("Seconds");
Days = new JRadioButton("Days");
Months = new JRadioButton("Months");
Years = new JRadioButton("Years");
TimeOfDayButtonGroup = new ButtonGroup();
DateButtonGroup = new ButtonGroup();
TimeOfDayButtonGroup.add(hours);
TimeOfDayButtonGroup.add(minutes);
TimeOfDayButtonGroup.add(seconds);
DateButtonGroup.add(days);
DateButtonGroup.add(months);
DateButtonGroup.add(years);
A) 1
B) 2
C) 3
D) 4
Hours = new JRadioButton("Hours");
Minutes = new JRadioButton("Minutes");
Seconds = new JRadioButton("Seconds");
Days = new JRadioButton("Days");
Months = new JRadioButton("Months");
Years = new JRadioButton("Years");
TimeOfDayButtonGroup = new ButtonGroup();
DateButtonGroup = new ButtonGroup();
TimeOfDayButtonGroup.add(hours);
TimeOfDayButtonGroup.add(minutes);
TimeOfDayButtonGroup.add(seconds);
DateButtonGroup.add(days);
DateButtonGroup.add(months);
DateButtonGroup.add(years);
A) 1
B) 2
C) 3
D) 4
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
33
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which contains several button components. If you want to add the buttons to the panel:
A) use the statement, panel.add(bGroup);
B) use the statement, bGroup.add(panel);
C) use the statement, Panel panel = new Panel(bGroup);
D) add each button to panel one at a time, e.g. panel.add(button1);
A) use the statement, panel.add(bGroup);
B) use the statement, bGroup.add(panel);
C) use the statement, Panel panel = new Panel(bGroup);
D) add each button to panel one at a time, e.g. panel.add(button1);
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
Event listeners must:
A) implement an interface
B) be included in private inner classes
C) not receive any arguments
D) exit the application once it has handled the event
A) implement an interface
B) be included in private inner classes
C) not receive any arguments
D) exit the application once it has handled the event
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
If button1 is a JButton object, which of the following statements will make its background blue?
A) button1.makeBackground(BLUE);
B) button1.setBackground(Color.BLUE);
C) button1.makeBackground(Color.BLUE);
D) button1.set.Background(BLUE);
A) button1.makeBackground(BLUE);
B) button1.setBackground(Color.BLUE);
C) button1.makeBackground(Color.BLUE);
D) button1.set.Background(BLUE);
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
When a component is added to a region in the BorderLayout manager:
A) the component retains its original size
B) it results in a compile time error, if it is too large
C) the component is stretched so it fills up the entire region
D) the region is resized to fit the component
A) the component retains its original size
B) it results in a compile time error, if it is too large
C) the component is stretched so it fills up the entire region
D) the region is resized to fit the component
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
You use the ________ key word in a class header to indicate that it implements an interface.
A) listener
B) interface
C) implements
D) static
A) listener
B) interface
C) implements
D) static
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following statements creates a class that is extended from the JFrame class?
A) JFrame DerivedClass = new JFrame();
B) class JFrame DerivedClass;
C) JFrame(DerivedClass);
D) public class DerivedClass extends JFrame{}
A) JFrame DerivedClass = new JFrame();
B) class JFrame DerivedClass;
C) JFrame(DerivedClass);
D) public class DerivedClass extends JFrame{}
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
When an application uses many components, rather than deriving just one class from the JFrame class, it is often better to encapsulate smaller groups of related components and their event listeners into their own class. A commonly used technique to do this is:
A) To extend a class from the JAbstractButton class to contain other components and their related code
B) To extend a class from the JComponent class to contain other components and their related code
C) To extend a class from the JPanel class to contain other components and their related code
D) To extend a class from the JFrame class to contain other components and their related code
A) To extend a class from the JAbstractButton class to contain other components and their related code
B) To extend a class from the JComponent class to contain other components and their related code
C) To extend a class from the JPanel class to contain other components and their related code
D) To extend a class from the JFrame class to contain other components and their related code
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
To include Swing and AWT components in your program, use the following import statements:
A) import java.swing; import java.awt;
B) import java.swing; import javax.awt;
C) import javax.swing; import java.awt;
D) import javax.swing; import javax.awt;
A) import java.swing; import java.awt;
B) import java.swing; import javax.awt;
C) import javax.swing; import java.awt;
D) import javax.swing; import javax.awt;
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
41
The System.exit method will end the application.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
Some of the common GUI components are buttons, labels, text fields, check boxes, and radio buttons.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
43
The following statement adds the FlowLayout manager to the container, centers the components, and separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
setLayout(new FlowLayout());
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
44
You would use this command at the operating system command line to execute the code in the MyApplication class and display the graphic image Logo·jpg as a splash screen.
A) java MyApplication Logo·jpg
B) java -splash:Logo·jpg MyApplication
C) java MyApplication -splash
D) java Logo·jpg -splash:MyApplication
A) java MyApplication Logo·jpg
B) java -splash:Logo·jpg MyApplication
C) java MyApplication -splash
D) java Logo·jpg -splash:MyApplication
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
The FlowLayout manager does not allow the programmer to align components.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
The ability to display splash screens was introduced in Java 6.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
47
All operating systems offer the same set of GUI components.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
You must use the statement import java.swing.*; in order to use the ItemListener interface.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
49
When an application uses many components, instead of extending just one class from the JFrame class, a better approach is to:
A) break the application into several smaller applications
B) reconsider the design of the application
C) encapsulate smaller groups of related components and their event listeners into their own classes
D) just go ahead and do it in one large class
A) break the application into several smaller applications
B) reconsider the design of the application
C) encapsulate smaller groups of related components and their event listeners into their own classes
D) just go ahead and do it in one large class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
When adding components to a container that is governed by the GridLayout manager:
A) you cannot specify a cell
B) you specify the cell with the row and column numbers in the add statement
C) you must add them starting with the lower, right cell
D) the components are added automatically by filling up the first column, then the second, etc.
A) you cannot specify a cell
B) you specify the cell with the row and column numbers in the add statement
C) you must add them starting with the lower, right cell
D) the components are added automatically by filling up the first column, then the second, etc.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
Check boxes may be grouped in a ButtonGroup, like radio buttons are.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
52
When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object that was generated in response to an event.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following statements is NOT true?
A) Radio buttons are round and check boxes are square.
B) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not.
C) Radio buttons implement ActionListener; Check boxes implement ItemListener.
D) All of these are true.
A) Radio buttons are round and check boxes are square.
B) Radio buttons are often grouped together and are mutually exclusive; Check boxes are not.
C) Radio buttons implement ActionListener; Check boxes implement ItemListener.
D) All of these are true.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
55
This is a graphic image that is displayed while an application loads into memory and starts up.
A) The Java 8 trademark screen
B) Memory usage screen
C) Blue screen of death
D) Splash screen
A) The Java 8 trademark screen
B) Memory usage screen
C) Blue screen of death
D) Splash screen
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
A common technique for writing an event listener class is to write it as a private inner class inside the class that creates the GUI.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
A GUI program automatically stops executing when the end of the main method is reached.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
What will be the result of executing the following statement?
Panel.setBorder(BorderFactory.createTitleBorder("Title"));
A) The JPanel referenced by panel will have an etched border with the title "Title" displayed on it.
B) The JPanel referenced by panel will have an empty border with the title "Title" displayed on it.
C) The JPanel referenced by panel will have a line border with the title "Title" displayed on it.
D) The JPanel referenced by panel will have a compound border with the title "Title" displayed on it.
Panel.setBorder(BorderFactory.createTitleBorder("Title"));
A) The JPanel referenced by panel will have an etched border with the title "Title" displayed on it.
B) The JPanel referenced by panel will have an empty border with the title "Title" displayed on it.
C) The JPanel referenced by panel will have a line border with the title "Title" displayed on it.
D) The JPanel referenced by panel will have a compound border with the title "Title" displayed on it.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
Why doesn't the following code compile correctly?
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Public class ColorCheckBoxWindow extends JFrame
{
Private JCheckBox greenCheckBox;
Private final int WINDOW_WIDTH = 300, WINDOW_HEIGHT = 100;
Public ColorCheckBoxWindow()
{
SetTitle("Green Check Box");
SetSize(WINDOW_WIDTH, WINDOW_HEIGHT);
SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GreenCheckBox = new JCheckBox("Green");
GreenCheckBox.addItemListener(new CheckBoxListener());
SetLayout(new FlowLayout());
Add(greenCheckBox);
SetVisible(true);
}
Public void itemStateChanged(ItemEvent e)
{
If (e.getSource() == greenCheckBox)
{
System.exit(0);
}
}
}
A) ColorCheckBoxWindow is not implementing the correct listener.
B) The button cannot be added to the content pane.
C) The itemStateChanged method cannot be coded here.
D) greenCheckBox should not be a private member.
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Public class ColorCheckBoxWindow extends JFrame
{
Private JCheckBox greenCheckBox;
Private final int WINDOW_WIDTH = 300, WINDOW_HEIGHT = 100;
Public ColorCheckBoxWindow()
{
SetTitle("Green Check Box");
SetSize(WINDOW_WIDTH, WINDOW_HEIGHT);
SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GreenCheckBox = new JCheckBox("Green");
GreenCheckBox.addItemListener(new CheckBoxListener());
SetLayout(new FlowLayout());
Add(greenCheckBox);
SetVisible(true);
}
Public void itemStateChanged(ItemEvent e)
{
If (e.getSource() == greenCheckBox)
{
System.exit(0);
}
}
}
A) ColorCheckBoxWindow is not implementing the correct listener.
B) The button cannot be added to the content pane.
C) The itemStateChanged method cannot be coded here.
D) greenCheckBox should not be a private member.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
60
Assume that the variable checkbox references a JCheckBox object. To determine whether the check box has been selected, use the following code:
A) if (isSelected(checkBox)) {/*code to execute, if selected*/}
B) if (checkBox.isSelected()) {/*code to execute, if selected*/}
C) if (checkBox) {/*code to execute, if selected*/}
D) if (checkBox.doClick()) {/*code to execute, if selected*/}
A) if (isSelected(checkBox)) {/*code to execute, if selected*/}
B) if (checkBox.isSelected()) {/*code to execute, if selected*/}
C) if (checkBox) {/*code to execute, if selected*/}
D) if (checkBox.doClick()) {/*code to execute, if selected*/}
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck