0

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;
    }
}
2
Contributors
8
Replies
9
Views
4 Years
Discussion Span
Last Post by empror9
Featured Replies
  • 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. Read More

0

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 by empror9

0

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 ..."

0

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

0

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.

0

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?

1

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 :)
0

ok thanks for your help :)

Edited by empror9

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.