I want the JLabel to change to a different text depending on what JButton I press, the problem is...it doesn't update, any help would be appreciated :smile.gif:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class labelUpdateTest extends JFrame implements ActionListener {
JLabel label;
public static void main(String[] args) {
new labelUpdateTest();
}
public labelUpdateTest()
{
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(200, 200);
JButton button1 = new JButton("BTN1");
JButton button2 = new JButton("BTN2");
label = new JLabel();
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent one)
{
label = new JLabel("1");
System.out.println("1");
}
});
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent two)
{
label = new JLabel("2");
System.out.println("2");
}
});
this.setLayout(new GridLayout(2,2));
this.add(button1);
this.add(button2);
this.add(label);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
}
}
to change the component's text.
Oh and unless you're expanding, you shouldn't need to implement ActionListener unless you're going to use it.
thanks dude :biggrin.gif:
have some diamonds:
to:
That was it! THANKS SO MUCH!