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

*q2: Write a public static method named q2 that takes no parameters and returns

ID: 3738927 • Letter: #

Question

*q2: Write a public static method named q2 that takes no parameters and returns a JPanel. * The panel will contain 1 JTextField with any number of columns, 1 JButton with any label, * and 1 JLabel. The panel will have functionality such that when a user enters a number into * the text field (we'11 call this value x) and presses the button the label will display the y-value of a parabola in standard form (https://www.desmos.com/calculator/zukjgk9iry) 0 where -6.09, b-0.04, and c0.38 at the x-value from the text field ik * Hint: If you store y in the wrapper class Double instead of the primitive double you can * call toString on it to convert it to a string that can be used as the text for the label * Tip: After clicking the button you may have to resize your window to see the result since 1 the frame will not automatically resize to fit the new text

Explanation / Answer

public static JPanel q2() { JPanel panel = new JPanel(); final JTextField textField = new JTextField(); JButton button = new JButton("click"); final JLabel label = new JLabel(); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(textField.getText()); label.setText("" + (((-6.09) * x * x) + (0.04 * x) + (0.38))); } }); panel.add(textField); panel.add(label); panel.add(button); return panel; }