You could also move the creation of annonymous action listeners to a helper method if you dont want to blow up your GUI creation method.
for example something like this:
public void initGUI() {
Button btnFile = new Button();
btn.addActionListener(get_file_actionListener());
Button btnEdit = new Button();
btn.addActionListener(get_edit_actionListener());
Button btnAbout = new Button();
btn.addActionListener(get_about_actionListener());
Button btnHelp = new Button();
btn.addActionListener(get_help_actionListener());
}
private ActionListener get_file_actionListener() {
return new ActionListener() { ... };
}
private ActionListener get_edit_actionListener() {
return new ActionListener() { ... };
}
private ActionListener get_about_actionListener() {
return new ActionListener() { ... };
}
private ActionListener get_help_actionListener() {
return new ActionListener() { ... };
}
Could maybe help to improve readability although in total it would be slightly
more code. Still less code then creating a new
actual class for each listener.