jQuery in Action, 3rd edition
The moose likes Mock Exam Errata and the fly likes event listners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "event listners" Watch "event listners" New topic

event listners

ronak mehta

Joined: Aug 14, 2001
Posts: 23
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
public void windowClosing(WindowEvent e) {
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
A) Compile time error
here i have one program and it says that when it will run it gives compile time error why?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Two reasons:
1) You have no import statements:
import java.awt.*;
import java.awt.event.*;
2) Since you are implementing WindowListener you need to implement the windowOpened(WindowEvent) method

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
ronak mehta

Joined: Aug 14, 2001
Posts: 23
thanks thomas
Asma Zafar
Ranch Hand

Joined: May 11, 2001
Posts: 49
you have to implement not only windowOpened but all the seven methods in the WindowListener interface apart from impoting the awt and awt.event classes.
Asma Zafar,
Sun Certified Java2 Programmer

Asma Zafar,<BR>Sun Certified Programmer for Java2 Platform
I agree. Here's the link: http://aspose.com/file-tools
subject: event listners
It's not a secret anymore!