addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );这里有一个匿名类。

解决方案 »

  1.   

    你的top也没有在NotHelloWorldFrame里声明啊下面的NotHelloWorldPanel就是放在NotHelloWorldFrame里声明啊。import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class NotHelloWorldFrame extends JFrame{
      //NotHelloWorldPanel f;
       public NotHelloWorldFrame(){ 
          setTitle("NotHelloWorld");
          setSize(300, 200);
          addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
           System.exit(0);
            }
          });      Container contentPane = getContentPane();
          contentPane.add(new NotHelloWorldPanel());
       }
       
       
       class NotHelloWorldPanel extends JPanel{
      public void paintComponent(Graphics g){ 
         super.paintComponent(g);
             g.drawString("Not a Hello, World program", 75, 100);
          }
       }}public class NotHelloWorld{
    public static void main(String[] args){
        JFrame frame = new NotHelloWorldFrame();
            frame.show();  
       }
    }class top extends JPanel{
    JLabel label;
    public top(String str){
    label=new JLabel("aaaa");
    label.setFont(new Font("",1,20));
    this.add(label);
    }

    }
      

  2.   

    NotHelloWorldFrame$1.class
    这个类叫匿名类吗?
      

  3.   

    class NotHelloWorldFrame extends JFrame{
      NotHelloWorldPanel f;
      top g;
       public NotHelloWorldFrame(){ 
          setTitle("NotHelloWorld");
          setSize(300, 200);
          addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
           System.exit(0);
            }
          });
    top和NotHelloWorldPanel在NotHelloWorldFrame里声明但NotHelloWorldPanel f;却报错不知为什么
      

  4.   

    NotHelloWorldFrame$1.class
    叫做匿名类啊,因为没有指定类名,所以生成的class的名字就在所附着的有名类的后面加上$符号再加上序号,有第二个匿名类就是NotHelloWorldFrame$2.class没问题啊import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class NotHelloWorldFrame extends JFrame{
      NotHelloWorldPanel f;
       public NotHelloWorldFrame(){ 
          setTitle("NotHelloWorld");
          setSize(300, 200);
          addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
           System.exit(0);
            }
          });      Container contentPane = getContentPane();
          contentPane.add(new NotHelloWorldPanel());
       }
       
       
       class NotHelloWorldPanel extends JPanel{
      public void paintComponent(Graphics g){ 
         super.paintComponent(g);
             g.drawString("Not a Hello, World program", 75, 100);
          }
       }}public class NotHelloWorld{
    public static void main(String[] args){
        JFrame frame = new NotHelloWorldFrame();
            frame.show();  
       }
    }class top extends JPanel{
    JLabel label;
    public top(String str){
    label=new JLabel("aaaa");
    label.setFont(new Font("",1,20));
    this.add(label);
    }

    }
      

  5.   


    不会有任何问题了
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class NotHelloWorldPanel extends JPanel
    {  public void paintComponent(Graphics g)
       {  super.paintComponent(g);
          g.drawString("Not a Hello, World program", 75, 100);
       }
    }class NotHelloWorldFrame extends JFrame
    {  NotHelloWorldPanel f;
       public NotHelloWorldFrame()
       {  setTitle("NotHelloWorld");
          setSize(300, 200);
          addWindowListener(new WindowAdapter()
             {  public void windowClosing(WindowEvent e)
                {  System.exit(0);
                }
             } );      Container contentPane = getContentPane();
          contentPane.add(new NotHelloWorldPanel());
       }
    }public class NotHelloWorld
    {  public static void main(String[] args)
       {  JFrame frame = new NotHelloWorldFrame();
          frame.show();  
       }
    }class top extends JPanel
    {
    JLabel label;
    public top(String str)
    {
    label=new JLabel("aaaa");
    label.setFont(new Font("",1,20));
    this.add(label);
    }

    }