When the following program is compiled:
the following errors are being shown: cannot find symbol variable panel 1 line 24 and 25Code :import javax.swing.*; import java.awt.*; import java.awt.event.*; public class del1 extends JFrame{ public del1() { JPanel panel1=new JPanel(); JButton button=new JButton("HI"); button.addActionListener(new ButtonHandler()); panel1.add(button); } private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event) { panel1.remove(0); // line24 panel1.add(new JButton("BYE")); // line 25 } }
Can't the variables of the main class be accessed from the inner class?
And when I change the inner class into an anonymous class, the error message displayed during compilation is: declare panel1 as final
When I do it and run the program ( by creating its object ) nothing is being displayed
