Deck 14: Introduction to Swing Components

Full screen (f)
exit full mode
Question
When setting a JFrame's size, part of the area is unusable because it is consumed by the JFrame's title bar and borders.
Use Space or
up arrow
down arrow
to flip the card.
Question
You can use the setEnabled() method to make a component unavailable and then make it available again in turn.
Question
An object that is interested in an event is called a source.
Question
The JLabel constructor ____ creates a JLabel instance with the specified image and horizontal alignment.

A) JLabel(String text, int horizontalAlignment)
B) JLabel(Icon image)
C) JLabel()
D) JLabel(Icon image, int horizontalAlignment)
Question
Java provides you with a Font class from which you can create an object that holds typeface and size information.
Question
The default behavior of a JFrame is to use the BorderLayout format, which divides a container into regions.
Question
You use the ____ method to obtain the title of a JFrame.

A) getTitle()
B) title()
C) setTitle()
D) setVisible()
Question
What is the default layout manager for JFrame?

A) BorderLayout
B) FlowLayout
C) FrameLayout
D) GridLayout
Question
What is the immediate parent class of JTextField?

A) JTextComponent
B) JComponent
C) Container
D) JFrame
Question
When creating a Font object, the typeface name must be enclosed in double quotation marks because it is a String.
Question
You can call a JFrame's setDefaultCloseOperation() method and use ____ as an argument to keep the JFrame visible and continue running the program.

A) JFrame.EXIT_ON_CLOSE
B) WindowConstants.DISPOSE_ON_CLOSE
C) WindowConstants.DO_NOTHING_ON_CLOSE
D) WindowConstants.HIDE_ON_CLOSE
Question
You define the text to be displayed in a tool tip by using the setToolTipText() method and passing an appropriate ____ to it.

A) Integer
B) Date
C) String
D) Boolean
Question
When a user closes a JFrame by clicking the Close button in the upper-right corner, the default behavior is for the JFrame to close and the application to terminate.
Question
When a JFrame is closed, you can end a program that you have forgotten to exit by typing Ctrl+E.
Question
The Swing classes are part of a more general set of UI programming capabilities that are collectively called the ____.

A) JavaX Classes
B) Java Foundation Classes
C) UI packages
D) Java Extension Libraries
Question
A ____ is a Component the user can click with a mouse to make a selection.

A) JCheckBox
B) JButton
C) JLabel
D) JComboBox
Question
To specify an italic font, you pass ____ to the constructor.

A) Font.ITALIC
B) Font.BOLD
C) PLAIN.ITALIC
D) ITALIC
Question
Each Swing component is a descendant of a JComponent.
Question
If a user enters more characters than specified in a JTextField, the extra characters scroll out of view.
Question
What class is the immediate parent of JFrame?

A) Container
B) Component
C) Frame
D) Window
Question
When constructing a Font object, which of the following arguments is NOT required?

A) typeface
B) style
C) weight
D) point size
Question
A(n) ____________________ consists of a label positioned beside a square; you can click the square to display or remove a check mark.
Question
The ____ method of JCheckBox sets the state of the JCheckBox to true for selected or false for unselected.

A) void setSelected(boolean)
B) boolean isSelected()
C) void setText(String)
D) String getText()
Question
Which of the following statements will change the value displayed in a JLabel named hello?

A) hello.setText("Hello");
B) setText.hello = "Hello"
C) hello = setText("Hello");
D) setText = hello
Question
A(n) ____________________ is the default appearance and behavior of any user interface.
Question
A component can be made available or unavailable by passing true or false to the ____ method.

A) getSource()
B) setEnabled()
C) setSelected()
D) setBounds()
Question
Swing components are UI elements such as dialog boxes and buttons. You can usually recognize their names because they begin with the letter ____________________.
Question
When you create a(n) ____, you can group several components, such as JCheckBoxes, so a user can select only one at a time.

A) CheckGroup
B) ButtonGroup
C) OptionBox
D) OptionGroup
Question
The ____ responds to keyboard events.

A) KeyListener
B) ActionListener
C) ChangeListener
D) FocusListener
Question
The JButton, JCheckBox, JComboBox, and JRadioButton components are associated with the ____ method.

A) addAdjustmentListener()
B) addChangeListener()
C) addWindowListener()
D) addItemListener()
Question
The ____ method of JComboBox returns the maximum number of items the combo box can display without a scroll bar.

A) getSelectedItem()
B) getItemCount()
C) getMaximumRowCount()
D) getSelectedIndex()
Question
A ____ is a component that combines two features: a display area showing an option, and a list box containing additional options.

A) JCheckBox
B) JComboBox
C) JButton
D) JTextBox
Question
Within an event-driven program, a component on which an event is generated is the ____ of the event.

A) handler
B) driver
C) listener
D) source
Question
The ActionListener interface contains the ____ method specification.

A) actionOccurred(Action e)
B) actionPerformed(ActionEvent e)
C) actionEvent(ActionEvent e)
D) action(Event e)
Question
A method that executes because it is called automatically when an appropriate event occurs is an event ____.

A) responder
B) listener
C) handler
D) source
Question
The ____________________ layout manager places components in a row, and when a row is filled, it automatically spills components into the next row.
Question
Which of the following statements will correctly set a JFrame named myFrame to be visible?

A) myFrame.Visible = True
B) myFrame.setVisible(true)
C) myFrame.Visibility.True
D) myFrame.true = Visible
Question
In a(n) ____________________ program, the user might initiate any number of events in any order.
Question
The ____ responds to keyboard focus events.

A) KeyListener
B) ActionListener
C) ChangeListener
D) FocusListener
Question
Within an implementation of the itemStateChanged() method, you can use the ____ method to determine which object generated the event, and the getStateChange() method to determine whether the event was a selection or a deselection.

A) getSource()
B) getEvent()
C) getItem()
D) getState()
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Require interaction with the local operating system
Question
Describe the FlowLayout manager.
Question
Provide an example of an event-driven program.
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A class that controls component positioning
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A JTextField that has the capability of accepting keystrokes
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Popup windows that can help a user understand the purpose of components in an application
Question
How have user interface components changed since the early versions of Java?
Question
How do you modify whether or not a JTextField can be edited?
Question
How do you change the font of a JLabel?
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
The measurement between lines of text in a single-spaced text document
Question
Write the statement to create a JLabel named welcome that holds the words "Welcome Home".
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A coffee-cup icon in the frame's title bar, and the Minimize, Restore, and Close buttons
Question
How can you customize the appearance of a JFrame?
Question
What are some of the decisions you must make when extending a JFrame?
Question
What are the four JFrame constructors?
Question
How do you change the text of a JLabel? Provide an example.
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A method that executes because it is called automatically when an appropriate event occurs
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Arial, Century, Monospaced, and Times New Roman
Question
What type of method must you implement when you register an event listener?
Question
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Are written completely in Java and do not have to rely on the local operating system code
Question
import javax.swing.*;
import java.awt.*;
public class JFrame4
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 250;
final int FRAME_HEIGHT = 100;
________________________
JFrame aFrame = new JFrame("Fourth frame");
aFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT); aFrame.setVisible(true);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel greeting = new JLabel("Good day");
________________________
aFrame.add(greeting);
}
}
In the first blank line provided, write the statement to create a Font object named myLook with a typeface of Times New Roman, italic, and 30-point size. In the second blank line, create the statement to apply myLook to the greeting JLabel.
Question
Assume you have declared a JFrame named welcomeFrame. Write the statement to set the welcomeFrame object's size to 300 pixels horizontally by 110 pixels vertically. Create a second statement to set the JFrame's title to display the text "My Sized Frame".
Question
import javax.swing.*;
public class JFrameLabel
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 120;
JFrame myFrame = new JFrame("Frame with label");
myFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
myFrame.setVisible(true);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_________________________
_________________________
}
}
The above code shows an application in which a JFrame is created and its size, visibility, and close operation are set. In the blank lines provided, write the code to create a JLabel named thanks that holds the words "Thank you for your business". Then, write the statement to add the JLabel to the JFrame.
Question
Write the statement to clear out a JTextField named myText.
Question
import javax.swing.*;
public class JFrameLook
{
public static void main(String[] args)
{
_________________________
JFrame myFrame = new JFrame("Look and Feel");
myFrame.setSize(300, 120);
myFrame.setVisible(true);
}
}
In the shaded line above, write the statement to set the JFrame's look and feel using the setDefaultLookAndFeelDecorated() method.
Question
Write the statement to create a layout manager named myLayout that centers components in each row.
Question
Write the statement to create a JButton named submitButton with the label "Submit your data".
Question
import javax.swing.*;
public class JFrame1
{
public static void main(String[] args)
{
JFrame aFrame = new JFrame("First frame");
aFrame.setSize(300, 125);
aFrame.setVisible(true);
}
}
The three shaded statements in the main() method above are important. Explain the purpose of each statement and why they are necessary for creating a JFrame.
Question
Write the code to build a JComboBox named sideDish with no arguments. Then, create the addItem() methods to provide options for "Fries", "Salad", and "Fruit".
Question
Write the statement to create a JCheckBox object named feeWaived that is selected. Include the label "Fee Waived".
Question
Write the statement to provide a JTextField object named myInfo that allows enough room for a user to enter 15 characters.
Question
import javax.swing.*;
import java.awt.*;
public class JFrame6
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 250;
final int FRAME_HEIGHT = 100;
JFrame aFrame = new JFrame("Sixth frame");
aFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
aFrame.setVisible(true);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel greeting = new JLabel("Hello");
JLabel greeting2 = new JLabel("Who are you?");
_________________________
aFrame.add(greeting);
aFrame.add(greeting2);
}
}
Using the above code, write the FlowLayout statement in the blank line provided that will display the two greeting JLabels side by side.
Question
Create the statements to construct two JFrames. One JFrame should be declared as welcomeFrame and have the title "Welcome", and the second JFrame should be declared as noTitleFrame and have no title.
Question
Write the statement to add a tool tip that displays "Submit your form" to a button named submit.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/74
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 14: Introduction to Swing Components
1
When setting a JFrame's size, part of the area is unusable because it is consumed by the JFrame's title bar and borders.
True
2
You can use the setEnabled() method to make a component unavailable and then make it available again in turn.
True
3
An object that is interested in an event is called a source.
False
4
The JLabel constructor ____ creates a JLabel instance with the specified image and horizontal alignment.

A) JLabel(String text, int horizontalAlignment)
B) JLabel(Icon image)
C) JLabel()
D) JLabel(Icon image, int horizontalAlignment)
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
5
Java provides you with a Font class from which you can create an object that holds typeface and size information.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
6
The default behavior of a JFrame is to use the BorderLayout format, which divides a container into regions.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
7
You use the ____ method to obtain the title of a JFrame.

A) getTitle()
B) title()
C) setTitle()
D) setVisible()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
8
What is the default layout manager for JFrame?

A) BorderLayout
B) FlowLayout
C) FrameLayout
D) GridLayout
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
9
What is the immediate parent class of JTextField?

A) JTextComponent
B) JComponent
C) Container
D) JFrame
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
10
When creating a Font object, the typeface name must be enclosed in double quotation marks because it is a String.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
11
You can call a JFrame's setDefaultCloseOperation() method and use ____ as an argument to keep the JFrame visible and continue running the program.

A) JFrame.EXIT_ON_CLOSE
B) WindowConstants.DISPOSE_ON_CLOSE
C) WindowConstants.DO_NOTHING_ON_CLOSE
D) WindowConstants.HIDE_ON_CLOSE
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
12
You define the text to be displayed in a tool tip by using the setToolTipText() method and passing an appropriate ____ to it.

A) Integer
B) Date
C) String
D) Boolean
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
13
When a user closes a JFrame by clicking the Close button in the upper-right corner, the default behavior is for the JFrame to close and the application to terminate.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
14
When a JFrame is closed, you can end a program that you have forgotten to exit by typing Ctrl+E.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
15
The Swing classes are part of a more general set of UI programming capabilities that are collectively called the ____.

A) JavaX Classes
B) Java Foundation Classes
C) UI packages
D) Java Extension Libraries
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
16
A ____ is a Component the user can click with a mouse to make a selection.

A) JCheckBox
B) JButton
C) JLabel
D) JComboBox
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
17
To specify an italic font, you pass ____ to the constructor.

A) Font.ITALIC
B) Font.BOLD
C) PLAIN.ITALIC
D) ITALIC
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
18
Each Swing component is a descendant of a JComponent.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
19
If a user enters more characters than specified in a JTextField, the extra characters scroll out of view.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
20
What class is the immediate parent of JFrame?

A) Container
B) Component
C) Frame
D) Window
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
21
When constructing a Font object, which of the following arguments is NOT required?

A) typeface
B) style
C) weight
D) point size
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
22
A(n) ____________________ consists of a label positioned beside a square; you can click the square to display or remove a check mark.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
23
The ____ method of JCheckBox sets the state of the JCheckBox to true for selected or false for unselected.

A) void setSelected(boolean)
B) boolean isSelected()
C) void setText(String)
D) String getText()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following statements will change the value displayed in a JLabel named hello?

A) hello.setText("Hello");
B) setText.hello = "Hello"
C) hello = setText("Hello");
D) setText = hello
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) ____________________ is the default appearance and behavior of any user interface.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
26
A component can be made available or unavailable by passing true or false to the ____ method.

A) getSource()
B) setEnabled()
C) setSelected()
D) setBounds()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
27
Swing components are UI elements such as dialog boxes and buttons. You can usually recognize their names because they begin with the letter ____________________.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
28
When you create a(n) ____, you can group several components, such as JCheckBoxes, so a user can select only one at a time.

A) CheckGroup
B) ButtonGroup
C) OptionBox
D) OptionGroup
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
29
The ____ responds to keyboard events.

A) KeyListener
B) ActionListener
C) ChangeListener
D) FocusListener
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
30
The JButton, JCheckBox, JComboBox, and JRadioButton components are associated with the ____ method.

A) addAdjustmentListener()
B) addChangeListener()
C) addWindowListener()
D) addItemListener()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
31
The ____ method of JComboBox returns the maximum number of items the combo box can display without a scroll bar.

A) getSelectedItem()
B) getItemCount()
C) getMaximumRowCount()
D) getSelectedIndex()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
32
A ____ is a component that combines two features: a display area showing an option, and a list box containing additional options.

A) JCheckBox
B) JComboBox
C) JButton
D) JTextBox
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
33
Within an event-driven program, a component on which an event is generated is the ____ of the event.

A) handler
B) driver
C) listener
D) source
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
34
The ActionListener interface contains the ____ method specification.

A) actionOccurred(Action e)
B) actionPerformed(ActionEvent e)
C) actionEvent(ActionEvent e)
D) action(Event e)
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
35
A method that executes because it is called automatically when an appropriate event occurs is an event ____.

A) responder
B) listener
C) handler
D) source
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
36
The ____________________ layout manager places components in a row, and when a row is filled, it automatically spills components into the next row.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following statements will correctly set a JFrame named myFrame to be visible?

A) myFrame.Visible = True
B) myFrame.setVisible(true)
C) myFrame.Visibility.True
D) myFrame.true = Visible
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
38
In a(n) ____________________ program, the user might initiate any number of events in any order.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
39
The ____ responds to keyboard focus events.

A) KeyListener
B) ActionListener
C) ChangeListener
D) FocusListener
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
40
Within an implementation of the itemStateChanged() method, you can use the ____ method to determine which object generated the event, and the getStateChange() method to determine whether the event was a selection or a deselection.

A) getSource()
B) getEvent()
C) getItem()
D) getState()
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
41
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Require interaction with the local operating system
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
42
Describe the FlowLayout manager.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
43
Provide an example of an event-driven program.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
44
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A class that controls component positioning
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
45
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A JTextField that has the capability of accepting keystrokes
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
46
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Popup windows that can help a user understand the purpose of components in an application
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
47
How have user interface components changed since the early versions of Java?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
48
How do you modify whether or not a JTextField can be edited?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
49
How do you change the font of a JLabel?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
50
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
The measurement between lines of text in a single-spaced text document
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
51
Write the statement to create a JLabel named welcome that holds the words "Welcome Home".
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
52
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A coffee-cup icon in the frame's title bar, and the Minimize, Restore, and Close buttons
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
53
How can you customize the appearance of a JFrame?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
54
What are some of the decisions you must make when extending a JFrame?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
55
What are the four JFrame constructors?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
56
How do you change the text of a JLabel? Provide an example.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
57
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
A method that executes because it is called automatically when an appropriate event occurs
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
58
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Arial, Century, Monospaced, and Times New Roman
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
59
What type of method must you implement when you register an event listener?
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
60
Match each term with the correct statement below.
a.point size
f.tool tips
b.layout manager
g.heavyweight components
c.lightweight components
h.fonts
d.window decorations
i.event handler
e.editable
Are written completely in Java and do not have to rely on the local operating system code
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
61
import javax.swing.*;
import java.awt.*;
public class JFrame4
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 250;
final int FRAME_HEIGHT = 100;
________________________
JFrame aFrame = new JFrame("Fourth frame");
aFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT); aFrame.setVisible(true);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel greeting = new JLabel("Good day");
________________________
aFrame.add(greeting);
}
}
In the first blank line provided, write the statement to create a Font object named myLook with a typeface of Times New Roman, italic, and 30-point size. In the second blank line, create the statement to apply myLook to the greeting JLabel.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
62
Assume you have declared a JFrame named welcomeFrame. Write the statement to set the welcomeFrame object's size to 300 pixels horizontally by 110 pixels vertically. Create a second statement to set the JFrame's title to display the text "My Sized Frame".
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
63
import javax.swing.*;
public class JFrameLabel
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 120;
JFrame myFrame = new JFrame("Frame with label");
myFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
myFrame.setVisible(true);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_________________________
_________________________
}
}
The above code shows an application in which a JFrame is created and its size, visibility, and close operation are set. In the blank lines provided, write the code to create a JLabel named thanks that holds the words "Thank you for your business". Then, write the statement to add the JLabel to the JFrame.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
64
Write the statement to clear out a JTextField named myText.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
65
import javax.swing.*;
public class JFrameLook
{
public static void main(String[] args)
{
_________________________
JFrame myFrame = new JFrame("Look and Feel");
myFrame.setSize(300, 120);
myFrame.setVisible(true);
}
}
In the shaded line above, write the statement to set the JFrame's look and feel using the setDefaultLookAndFeelDecorated() method.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
66
Write the statement to create a layout manager named myLayout that centers components in each row.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
67
Write the statement to create a JButton named submitButton with the label "Submit your data".
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
68
import javax.swing.*;
public class JFrame1
{
public static void main(String[] args)
{
JFrame aFrame = new JFrame("First frame");
aFrame.setSize(300, 125);
aFrame.setVisible(true);
}
}
The three shaded statements in the main() method above are important. Explain the purpose of each statement and why they are necessary for creating a JFrame.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
69
Write the code to build a JComboBox named sideDish with no arguments. Then, create the addItem() methods to provide options for "Fries", "Salad", and "Fruit".
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
70
Write the statement to create a JCheckBox object named feeWaived that is selected. Include the label "Fee Waived".
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
71
Write the statement to provide a JTextField object named myInfo that allows enough room for a user to enter 15 characters.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
72
import javax.swing.*;
import java.awt.*;
public class JFrame6
{
public static void main(String[] args)
{
final int FRAME_WIDTH = 250;
final int FRAME_HEIGHT = 100;
JFrame aFrame = new JFrame("Sixth frame");
aFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
aFrame.setVisible(true);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel greeting = new JLabel("Hello");
JLabel greeting2 = new JLabel("Who are you?");
_________________________
aFrame.add(greeting);
aFrame.add(greeting2);
}
}
Using the above code, write the FlowLayout statement in the blank line provided that will display the two greeting JLabels side by side.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
73
Create the statements to construct two JFrames. One JFrame should be declared as welcomeFrame and have the title "Welcome", and the second JFrame should be declared as noTitleFrame and have no title.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
74
Write the statement to add a tool tip that displays "Submit your form" to a button named submit.
Unlock Deck
Unlock for access to all 74 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 74 flashcards in this deck.