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;
    }
}

there is no error message, when i press the compile button nothing happen at all.

this is the message "BUILD SUCCESSFUL (total time: 0 seconds)"

i can create a simple programme and compile it but in ActionListener not

Edited 4 Years Ago by empror9

Sorry to keep asking, but it's important that we get this straight. Which of the following two statements is true?
1: when i press the compile button nothing happens at all.
2. when i press the compile button I get the message "BUILD SUCCESSFUL ..."

when i press the compile button it shows "BUILD SUCCESSFUL (total time: 0 seconds)" and thats it!

i think my problem in the main class

That looks like it compiles correctly but when it executes it does nothing. Your main method has no executable statements in it, so of course it doesn't do anything. But if you are running this as an Applet then main isn't relevant.

then how to fix this error? by the way i didn't write the code, i want just to test and learn from it. i need to compile it

do you have any way to fix that?

You did compile it. Now you need to execute it. You fill find many many tutorials on the web on how to execute a Java applet.

Comments
thank you :)
This question has already been answered. Start a new discussion instead.