?
Solved

Question on event listeners ..

Posted on 2002-04-19
1
Medium Priority
?
222 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 100 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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