1

Here is a code that i am trying to compile.all i get is error like this

s09_02 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener.

So my question is, how can I implement ActionListener into my class (s09_02) if the class is not abstract?

Here is the entire code: (Because I have no idea where the problem could be)

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class s09_02 extends Applet implements ActionListener{
public void init()
 {
  setLayout(null);
  setBackground(new Color(0,10,100));
 }
 public void paint(Graphics p){String t=null;
 int x,y,w,h,r,g,b;
 t=getParameter("xx");
 x=Integer.parseInt(t);
 t=getParameter("yy");
 y=Integer.parseInt(t);
 t=getParameter("ww");
 w=Integer.parseInt(t);
 t=getParameter("hh");
 h=Integer.parseInt(t);
 t=getParameter("rr");
 r=Integer.parseInt(t);
 t=getParameter("gg");
 g=Integer.parseInt(t);
 t=getParameter("bb");
 b=Integer.parseInt(t);
 p.setColor(new Color(r,g,b));
 p.fillRect(x,y,w,h);

} }

<html>
<body>
<applet code="s09_02.class" width=400 height=400>
<param name="xx" value="25"><param name="yy" value="25">
<param name="ww" value="150"><param name="hh" value="150">
<param name="rr" value="0"><param name="gg" value="150">
<param name="bb" value="100">
</applet>
</body>
</html>


Also suggest me what changes should i make in this code so that code runs properly ??
Thanks...
mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3046211
  • 466
  • 2
  • 13
  • Do what the compiler told you: implement the method `public void actionPerformed(ActionEvent ae){}`. – Jared Apr 03 '14 at 04:06
  • 1) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See my answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. – Andrew Thompson Apr 04 '14 at 05:06

2 Answers2

3

You need to add public void actionPerformed(ActionEvent e){} in you code as you are implementing ActionListner.

ActionListner is an interface so you need to override the abstract methods of ActionListner

If you are not using any event then remove the implements ActionListner from your code.

CHOCKO
  • 109
  • 4
2

You need to implement the method

    @override
public void actionPerformed(ActionEvent e){
//code that dose something
}

http://docs.oracle.com/javase/7/docs/api/java/awt/event/ActionListener.html