Answer the question
In order to leave comments, you need to log in
How to set a class as an argument?
Hello everyone
Tell me, who knows how to submit a class as an argument? Probably not quite correctly expressed the question, the example below explains:
I have a method that changes the listener for buttons:
void changeListeners(ArrayList<JButton> buttons, Object className) {
ActionListener[] listeners;
for (JButton btn:buttons) {
listeners = btn.getActionListeners();
for (ActionListener l:listeners) {
btn.removeActionListener(l);
}
btn.addActionListener(new className.getClass()); //знаю что такая конструкция может все сломать
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question