Greetings All
I am a C++ programmer and currently learning Java.
While playing around with event management I always find that I have an unused variable in the ActionEvent(). For example:
import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public class ExampleProgram extends JFrame { ExampleProgram(){ setDefaultCloseOperation(EXIT_ON_CLOSE); initGui(); return; } public static void main(String args[]){ ExampleProgram w = new ExampleProgram(); w.setVisible(true); return; } private void initGui(){ JButton b = new JButton(); b.setText("Click Me!"); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt){ doStuff(evt); } }); this.add(b); this.setSize(300,200); return; } private void doStuff(ActionEvent evt){ System.out.println("Yeah!"); return; } } }
Variable evt is always unused. All my coding experience tells me that unused variables are a horrible thing to see and so should always be removed. At least this is what I do in C++.
Am I missing something, doing something fundamentally wrong or just being silly?
I welcome any and all advice.
Regards
Nikki