Note that there are some explanatory texts on larger screens.

plurals
  1. POanonymous class turned into inner class
    text
    copied!<p>I'm being asked to transform an anonymous button class into an inner button class. The text I'm given to read discusses this topic using examples incorporating an <code>ActonListener</code>. However, the code I'm being asked to modify does not have an <code>ActonListener</code> in it. So I'm having difficulty following what I'm supposed to do. How do I take the following code and convert an anonymous to an inner class. does my button code even have an anonymous class in it? </p> <p>Caveat: Don't just type up an answer for me. I need to learn this. Please help point me in the right direction. </p> <p>Here's my code:</p> <pre><code>package ui.panels; import java.awt.Panel; import interfaces.Resettable; import model.Model; import ui.panels.ButtonPanel; public class ControlsPanel extends Panel implements Resettable{ private ButtonPanel btnPanel; public ControlsPanel (Model model) { btnPanel = new ButtonPanel(model); add(btnPanel); } public void resetComponents() { } } </code></pre> <p>And here is "ButtonPanel.java"</p> <pre><code>package ui.panels; import java.awt.Button; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import model.Model; public class ButtonPanel extends Panel { private Button btnClear; public ButtonPanel(final Model model) { btnClear = new Button("Clear"); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { model.resetComponents(); model.repaint(); } }); add(btnClear); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload