Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
downloads directory/folder). In most browsers/OSs, the
easiest way to do this is by right-clicking/control-clicking on
each of the links above and then selecting Converter.java.
ConverterWindow that is a specialization
of the JFrame class. (Note: This class must
import
java.awt.*, java.awt.event.*,
and javax.swing.*.)
String literal "Converter".
setupWindow().
setupLayout().
setupLayout() method,
add a declaration for a local variable named contentPane
that is a Container.
setupLayout() method,
assign the result of a call to the parent's getContentPane()
to the local variable named contentPane?
super.?
setupWindow() method, call the
setDefaultCloseOperation() method (inherited from the
parent) passing it the value EXIT_ON_CLOSE (inherited
from the parent).
setupWindow() method, call the
setSize() method (inherited from the
parent) passing it the values 400 and 200.
setupWindow() method, call the
setVisible() method (inherited from the
parent) passing it the values true.
setupLayout() method.
setupWindow() method.
ConverterWindow.
Converter.
setupLayout() method,
call the contentPane object's setLayout()
method and pass it the reference null.
ConverterWindow class,
a JButton named convertButton,
a JLabel named kilometersLabel, and
a JTextField named milesField.
setupLayout() method,
construct a JButton
(passing the constructor the String literal
"Convert") and assign it to convertButton.
setupLayout() method,
call the convertButton object's
setBounds() method passing it the values
250,125,100,30.
setupLayout() method,
call the contentPane object's
add() method passing it convertButton.
ConverterWindow and execute Converter.
setupLayout() method,
construct kilometersLabel (with text
"0"), set its bounds to 225,25,100,30,
and add it to contentPane.
setupLayout() method,
construct milesField (with text
"0"), set its bounds to 25,25,100,30,
and add it to contentPane.
ConverterWindow and execute Converter.
JButton objects?
(Hint: This was discussed in lecture.)
ConverterWindow class implements
that interface.
ConverterWindow class.
String variables named
milesString and kilometersString, and
double variables named miles and
kilometers.
milesField
and assigns it to milesString.
milesString
to a double, assigns that value to miles,
coverts miles to kilometers (there are 1.60934
kilometers per mile), and assigns an appropriately formatted
String to kilometersString. If
milesString can't be converted, assign "N/A" to
kilometersString. (Hint: Use
Double.parseDouble() in a try-catch block.)
kilometersLabel
to kilometersString.
ConverterWindow and execute Converter.
ConverterWindow, in an appropriate
place, call the convertButton object's
addActionListener() method passing it the
reference this.
ConverterWindow and execute Converter.
ConverterApplet that extends
the JApplet class and implements the
ActionListener interface. (Note: This class should
import
java.awt.*,
java.awt.event.*, and javax.swing.*.)
actionPerformed() method, and
setupLayout() method from
the ConverterWindow class.
setupLayout() method.
ConverterApplet class?
ConverterApplet.
converter.html into the browser of your choice
(e.g., using File+Open File).
ConverterApplet and ConverterWindow
classes have much code in common?
Copyright 2025