When I run the following code, I get a runtime error saying it can't find main.
However, if I separate these two classes into 2 separate files, with class myCodeToHandleWinClose also having the import java.awt.event.*; at the top, and run FrameDemo, it runs fine and calls the WindowClosing method. Why doesn't it run as it appears below, with both classes in the same FrameDemo.java file?
import javax.swing.*;
import java.awt.event.*;
public class FrameDemo
{
public static void main(
String[] args)
{
JFrame jframe = new JFrame("Example");
jframe.setSize(400,100);
jframe.setVisible(true);
myCodeToHandleWinClose m = new myCodeToHandleWinClose();
jframe.addWindowListener(m);
}
}
class myCodeToHandleWinClose implements WindowListener
{
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowClosed(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}