I need some help, as I am quite the noob.
The program im trying to make here, used to work for my intentions, but as I tried to make my code more readable, I ran into a problem regarding ActionListener
.
Before I made a new class to have all the methods in, I used button.addActionListener(this);
and it worked just fine. Now that I wanted to put things in a separate class, I have absolutely no idea what to do.
So I guess my question is, how can I make ActionListener
work in a situation like this, or am I just doing everything wrong here?
Here's the part of my code that I think is relevant(edited out most of it):
//Class with frame, panels, labels, buttons, etc.
class FemTreEnPlus {
FemTreEnPlus() {
//Components here!
//Then to the part where I try to add these listeners
cfg.addActionListener();
Exit.addActionListener();
New.addActionListener();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run(){
//Start the Program in the FemTreEnPlus Class
new FemTreEnPlus();
}
});
}
That was the class with the frame, here's the other class, with the methods
public class FemTreEnMethods extends FemTreEnPlus implements ActionListener {
//Perform Actions!
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == cfgButton){
configureSettings();
}
if(ae.getSource() == newButton){
newProject();
}
if(ae.getSource() == exitButton){
exitProgram();
}
}
//All methods are down here
Thanks in advance for any help.