Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the result of running the following program? import java.awt.event.ActionEvent; import javax.swing.JButton; public class SimpleEvents { private int changeValue = -1; public static void

What is the result of running the following program? import java.awt.event.ActionEvent; import javax.swing.JButton; public class SimpleEvents { private int changeValue = -1; public static void main(String[] args) { new NoSwitch(); } public SimpleEvents() { WidgetViewer wv = new WidgetViewer(); JButton sophie = new JButton("5"); JButton jack = new JButton("-5"); sophie.addActionListener(new ButtonHandler(jack)); jack.addActionListener(new ButtonHandler(sophie)); wv.add(sophie, 10, 50, 70, 20); wv.add(jack, 10, 80, 70, 20); } class ButtonHandler extends WidgetViewerActionEvent { private JButton buttonToChange; public ButtonHandler(JButton myButton) { buttonToChange = myButton; } @Override public void actionPerformed(ActionEvent e) { String s = buttonToChange.getText(); int val = Integer.parseInt(s); val += changeValue; buttonToChange.setText(String.valueOf(val)); } } }

The program will compile, but will have a runtime error when a button is clicked because JButton is immutable. ? When the user clicks one button, the other button is modified. ? The program will not compile because ButtonHandler must be defined above its use. ? The program will compile, but will have a runtime error when a button is clicked because an event handler for one button cannot modify a different button. ? The program will not compile because an event handler can have only an actionPerformed method. ? When the user clicks a button, it is modified. ? The program will compile, but will have a runtime error because only one instance of an event handler class can be instantiated. ? The program will not compile because no class except SimpleEvents can access its private instance variable.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions