主题:[讨论]class WindowMonitor 问题
public class NotePad extends JFrame
{
public static void main(String[]args)
{
final NotePad frame =new NotePad();
......
WindowMonitor monitor=new WindowMonitor();
frame.addWindowListener(monitor);
}
class WindowMonitor extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
int len=JOptionPane.showConfirmDialog(NotePad.this,
"The file has not been save,do you want to save it?",
"choose one",JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if(len==JOptionPane.YES_OPTION)
{
saveFile();
System.exit(0);
}
else if(len==JOptionPane.NO_OPTION)
{
System.exit(0);
}
}
}
}
为什么编译出错
No enclosing instance of type NotePad is accessible. Must qualify the allocation with an enclosing instance of type NotePad (e.g. x.new A() where x is an instance of NotePad).
该怎么改
{
public static void main(String[]args)
{
final NotePad frame =new NotePad();
......
WindowMonitor monitor=new WindowMonitor();
frame.addWindowListener(monitor);
}
class WindowMonitor extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
int len=JOptionPane.showConfirmDialog(NotePad.this,
"The file has not been save,do you want to save it?",
"choose one",JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if(len==JOptionPane.YES_OPTION)
{
saveFile();
System.exit(0);
}
else if(len==JOptionPane.NO_OPTION)
{
System.exit(0);
}
}
}
}
为什么编译出错
No enclosing instance of type NotePad is accessible. Must qualify the allocation with an enclosing instance of type NotePad (e.g. x.new A() where x is an instance of NotePad).
该怎么改