I am trying to update the text on the label through the use of the actionListener, however no matter what i do i can't get it to work.
Here is the relevent code
public JPanel panel(){ JPanel panel = new JPanel(); panel.add(label()); panel.setPreferredSize(new Dimension(100,100)); panel.add(button()); return panel; } public JLabel label(){ JLabel label = new JLabel(); label.setText("Some Updating text: "+i); return label; } public JButton button(){ JButton button = new JButton(); button.setPreferredSize(new Dimension(20,20)); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ i = i+1; label().repaint(); } }); return button; }
Any help on this issue will be appreciated.