Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ActionListener Error - Help please

807599Nov 13 2006 — edited Nov 13 2006
I'm fairly new to java but I don't understand why I'm getting this ActionListener Error:
Event4.java:7: Event4 is not abstract and does not override abstract method acti
onPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class Event4 extends JFrame implements ActionListener

I'm supposed to create an inner class object that will respond to events
Here is my code:
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class Event4 extends JFrame implements ActionListener
{
	private JButton myButton;

	public static void main (String[ ] args)
	{
		JFrame f = new Event4( );
		f.setDefaultCloseOperation(EXIT_ON_CLOSE);
		f.setSize(250,170);
		f.setVisible(true);
	}

	public Event4( )
	{
		super("Event Demo 4");
		getContentPane( ).setLayout(new FlowLayout( ));
		myButton = new JButton("Example");
		
		getContentPane( ).add(myButton);
		myButton.addActionListener(new
			ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					getContentPane().setBackground(Color.RED);
				}


			});
		
	}

	
}
Any help is greatly appreciated, thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2006
Added on Nov 13 2006
4 comments
309 views