**This is my Situation**
1. I want to make my Frame close when the user clicks the “x”.
2. To give the Frame this capability, I think that I need to call the Frame’s .addWindowListener method prior to displaying the Frame.
3. addWindowListener requires an object that implements the Interface WindowListener. WindowAdapter implements WindowListener, and WindowAdapter has the method WindowClosing (which is what I need). But unfortunately WindowAdapter is abstract.
4. Because Window Adapter is abstract, I created a class called SimpleWindowAdapter:
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SimpleWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
5. After making SimpleWindowAdapter I put this in Main and it compiled:
SimpleWindowAdapter mySimpleWindowAdapter= new SimpleWindowAdapter();
6. Then I added this to Main:
myFrame.addWindowListenter(mySimpleWindowAdapter);
7. I got this error:
AddWindowListener(SimpleWindowAdapter) is undefined for the type Frame
**This is my question**
AddWindowListener requires an object that implements WindowListener. SimpleWindowAdapter’s parent does implement that Interface. So why am I getting an error??
1. I want to make my Frame close when the user clicks the “x”.
2. To give the Frame this capability, I think that I need to call the Frame’s .addWindowListener method prior to displaying the Frame.
3. addWindowListener requires an object that implements the Interface WindowListener. WindowAdapter implements WindowListener, and WindowAdapter has the method WindowClosing (which is what I need). But unfortunately WindowAdapter is abstract.
4. Because Window Adapter is abstract, I created a class called SimpleWindowAdapter:
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SimpleWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
5. After making SimpleWindowAdapter I put this in Main and it compiled:
SimpleWindowAdapter mySimpleWindowAdapter= new SimpleWindowAdapter();
6. Then I added this to Main:
myFrame.addWindowListenter(mySimpleWindowAdapter);
7. I got this error:
AddWindowListener(SimpleWindowAdapter) is undefined for the type Frame
**This is my question**
AddWindowListener requires an object that implements WindowListener. SimpleWindowAdapter’s parent does implement that Interface. So why am I getting an error??