0
How do you use event handler in a separate class?
I have a separate Handler class, that implements ActionListener. It overrides the actionPerformed method and everything is candies and butterflies. But wtf i use it in different class: button.addActionListener(new Handler()); And it screams „couldn’t resolve symbol „Handler”.. What am I supposed to do?
8 Antworten
0
Did you make sure to import it?
0
This is swing or javafx?
I assume it's Swing.
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// do something
}
});
you should do something in this way.
0
This is Swing. Now, while i fiddled around:
I have a separate Controller class, in which i put the Handler class. In this case, first forces me to write Controller.Handler()
And after that, it says „Controller is nit an enclosing class” ( dunno what that even means)
When I take the Handler class outside the Controller, I can use the Handler() just fine.
But this is incorrect solution, I need to make the Controller in charge of action listening..
0
Ok I had to declare the Handler class as static…
But guys thanks anyway, it just tend to be so frustrating.
0
What does swing use for its gui? Just asking, I mean javafx uses fxml files.
0
I only know it uses the javax.swing library for layouts and JComponents, unfortunately I’m still learning and don’t know the low level details
0
Okayy
0
I dont knos swing, but im currently working with stuff like this in python. If your event listener is in the class Handler, then you might be able to reference it by class (ie, Handler.your_event_listener) also the keywords self,root,parent, children etc can be helpful as well... just what ive learned (with python at least)