Solved

Question on event listeners ..

Posted on 2002-04-19
1
200 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
ID: 6953941
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HSSFWorkbook cannot be resolved error 10 66
jdbc error in jsp application 20 44
Error in @AspectJ Based AOP with Spring 2 13
CSV file parsing thru Java 13 26
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

786 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