Originally Posted by
KevinWorkman
It has to be final so that it can be accessed inside your ActionListener, which is called an anonymous inner class. Another way to do it, without the final (actually I'd recommend the final anyway, just because you don't plan on changing the variable ever), and to narrow the scope, would be something like this:
helpAction.addActionListener(new ActionListener()
{
final HelpFrame popOut0=new HelpFrame();
popOut0.setSize(600,400);
popOut0.setResizable(false);
popOut0.setBackground(Color.white);
popOut0.setForeground(Color.black);
popOut0.setAlwaysOnTop(true);
popOut0.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
popOut0.setLocation(20,40);
popOut0.setVisible(false);
public void actionPerformed(ActionEvent arg0)
{
popOut0.show(true);
}
});
That way your outer class doesn't have to worry about the HelpFrame at all. Another way to do this would be to just write another outer class for the ActionListener.
Edit- Okay, that stuff might not be allowed to go there, so you could put it in a constructor or a declaration block. But you get the gist.
Thanks again - we did something about anonymous inner-classes at some point during my studies, I'm just showing that I understand what's meant by that by implementing it in my project.
Still so much to do, probably more questions to follow!
Regards,
Shaun.