Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

* q2: Write a public class named LayerListener that implements the ActionListene

ID: 3702917 • Letter: #

Question

* q2: Write a public class named LayerListener that implements the ActionListener interface. This class will have a public constructor that takes a JTextField and a JLabel as * parameters and stores these in instance variables. Override the actionPerformed method to * interpret the text on the JTextField as an x-value (as a double) and display the corresponding y-value on the JLabel for the line with slope 1.67 and y-intercept 6.52. e another Class named Main. This Main contain a GUI should that you can do as many modification as you want. This GUI need to interact with the class LayerListenr and display the *result on the JLabel in this GUI.

Explanation / Answer

import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class LayerListener implements ActionListener { private JTextField textField; private JLabel label; public LayerListener(JTextField textField, JLabel label) { this.textField = textField; this.label = label; } @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(textField.getText()); label.setText(Double.toString((1.67 * x) + 6.52)); } }