There is a string in JFrame
, the value of which needs to be constantly updated when a button is pressed, but this does not work.
How to implement it?
Button :
class Button extends JFrame() { JButton button; JTextArea text; Listining l = new Listining(); public Button(String s) { super(s); //Вызываем исходник int a; setLayout(new FlowLayout()); button = new JButton("Та самая кнопка"); text = new JTextArea(a); add(button); add(text); button.addActionListener(l); } }
ActionListener :
public class Listining implements ActionListener { public void actionPerformed(ActionEvent e) { try { if (e.getSource() == button) { a++; } } catch(Exception ex) { JOptionPane.showMessageDialog(null, "Error, sorry."); } } }