Action d = new AbstractAction("exit")
              {
                  public void actionPerformed(ActionEvent event)
                  {
                      System.exit(0);
                  }
              };
不能直接这样写

解决方案 »

  1.   

    import java.io.*; 
    class exceptiondemo
    {
    public static void main(String args[])throws IOException 
    {
    FileInputStream fis = null;  
    try
    {
    System.out.println("first argument is "+args[0]); 
    fis = new FileInputStream("text.txt");    
    System.out.println("content of text is :");
    int b;
    while((b=fis.read())!= -1) 
    {
    System.out.print((char)b);
    }
    }
    catch(FileNotFoundException e)

    System.out.println(e);  
    }
    catch(IOException e)
    {
    System.out.println(e);
    }
    catch(IndexOutOfBoundsException e)

    System.out.println("closing fileinputstream.."); 
    }
    finally
    {
    if (fis != null)
    {
    fis.close(); 
    }
    else
    {
    System.out.println("fileinputstream not open");
    }
    }
    }
    }
      

  2.   

    因为你的变量d被用了两次,
    一次是:d=new Button("close");另一次是:Action d = new AbstractAction("exit")而f.add(d,BorderLayout.EAST);这里面的d应该是个Component,而不是Action.你需要把变量名换一换.