Solved

Question on event listeners ..

Posted on 2002-04-19
1
196 Views
Last Modified: 2010-03-31
Hi,

I'm learning Java and have understood that you have to 'implement' any listeners in the class definition to be able to use them.

ie public class ChangeTitle extends JFrame implements ActionListener

I have just entered and run a book example that implements the ActionListener event handler, but not only does the class use the 'addActionListener' method in the class constructor, but in the main() definition for the class it ALSO uses 'addWindowListener' ?????

How can this class use the WindowListener if hasn't 'implemented' it in the class definition.

ie shouldn't the class definition should be ;

public class ChangeTitle extends JFrame implements ActionListener, WindowListener

instead of

public class ChangeTitle extends JFrame implements ActionListener

The small program compiles and runs okay.
0
Comment
Question by:Cacker
1 Comment
 
LVL 15

Accepted Solution

by:
ozymandias earned 25 total points
Comment Utility
JFrame is a subclass of java.awt.window which has a method called addWindowListener(). The method you see in the JFrame is calling that method. It is a feature of inheritance.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now