hello,
i'm leaning about ActionListener but i can't compile my code, i don't know why :(
this is the code
package javaapplication7;
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Test extends Applet implements ActionListener{
Button b1=new Button("Red");
Button b2=new Button("Green");
Button b3=new Button("Blue");
Label l1=new Label("Smith");
@Override
public void init(){
b1.setBackground(Color.red);
b2.setBackground(Color.green);
b3.setBackground(Color.blue);
add(b1);
add(b2);
add(b3);
add(l1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1)
l1.setForeground(Color.red);
else if(e.getSource()==b2)
l1.setForeground(Color.green);
else if(e.getSource()==b3)
l1.setForeground(Color.blue);
}
public static void main(String[] args) {
// Test t;
}
}