Answer the question
In order to leave comments, you need to log in
Error while trying to get text of JButton (java)?
There is a JFrame, it has a large number of JButtons. Each Jbutton has an ActionListener attached to it.
Button example:
static JButton one = new JButton("1");
public static void main(String[] args) {
one.addActionListener(new equation());
}
class equation implements ActionListener {
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand().getText(); // =ошибка
}
}
Answer the question
In order to leave comments, you need to log in
That's right, the ActionEvent.getActionCommand() method returns a string. The string does not have a getText method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question