• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

event listners

 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks thomas
 
Asma Zafar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic