Note that there are some explanatory texts on larger screens.

plurals
  1. POSome doubts about visibility of the variable inside an inner class declared in a method
    primarykey
    data
    text
    <p>I have the following doubt related to how work this method:</p> <pre><code>protected JButton createToolbarButton(String name, final String id, final JPanel panel) { JButton button = new JButton(name); // Create a new JButton // If the passed Jpanel named "panel" exist, add this to the JPanel named content (the CardLayout container) if (panel != null) content.add(panel, id); else button.setEnabled(false); // Otherwise disable this button button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //System.out.println(panel.getClass()); if (panel instanceof SchedulingPanel) ((SchedulingPanel)panel).getTasksSettings().fireSettingsUpdated(); else if (panel instanceof EventsPanel) ((EventsPanel)panel).refreshPanel(); else if (panel instanceof ConfigurationPanel) ((ConfigurationPanel)panel).refreshPane(); showSection(id); } }); return button; } </code></pre> <p>I have this method named <strong>CreateToolbarButton</strong> that have some input parameters including the <strong>String id</strong> parameter.</p> <p>As you can see in this method I add an <strong>ActionListener inner class</strong> to my JButton object (that handles the click event on this button).</p> <p>Inside this <strong>ActionListener inner class</strong> it is declared the <strong>actionPerformed()</strong> method that handle the click event and at the end of this method it call the <strong>showSection(id)</strong> method passing to id the <strong>id</strong> paramether that seems to be the same one of the <strong>createToolbarButton()</strong> input paramether.</p> <p>So it seems to me that inside my <strong>ActionListener inner class</strong> I have visibility also of the paramether and variable of the container method (<strong>createToolbarButton()</strong>)</p> <p>Is it right? Why? it seems a litle strange to me</p> <p>Tnx</p> <p>Andrea</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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