Consider the following code snippet that is supposed to show the total order amount when the button is clicked:
Public static void main(String[] args)
{
Final Order myOrder = new Order() ;
JButton button = new JButton("Calculate") ;
Final JLabel label = new JLabel("Total amount due") ;
) . .
Class MyListener implements ActionListener
{
Public void actionPerformed(ActionEvent event)
{
Label.setText("Total amount due " + myOrder.getAmountDue() ) ;
}
}
ActionListener listener = new MyListener() ;
}
What is wrong with this code?
A) button should be declared as final
B) The listener has not been attached to the button.
C) The listener cannot access the methods of the myOrder object.
D) The listener cannot access the methods of the label object.
Correct Answer:
Verified
Q22: Consider the following code snippet:
Public class ClickListener
Q23: What's the difference between a text field
Q24: Which statement will add a dollar sign
Q27: To build a user interface that contains
Q28: If a text field holds an integer,
Q30: Which of the following statements creates a
Q47: Event listeners are often installed as _
Q60: Consider the following code snippet: JFrame frame
Q75: A(n) _ has an instance method addActionListener()
Q76: How do you specify what the program
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents