童真模式启动 2017-06-02 14:29 采纳率: 0%
浏览 924
已采纳

JAVA中,下面一段关于“通过流完成数据文件读取与显示”的代码,为什么不能正常编译呢?

 import java.awt.*;
import java.awt.event.*;
import java.awt.Color.*;
import java.io.*;

class File extends Frame implements FocusListener,ActionListener
{
    TextArea ta=new TextArea("",10,30);
    TextField tf=new TextField(30);
    Button b=new Button("读取数据");


    File()
    {

        this.add(ta,"North");
        this.add(tf,"Center");
        this.add(b,"South");

        tf.addFocusListener(this);
        tf.setText("在此输入文件路径…");
        tf.setForeground(Color.gray);

        b.addActionListener(this);

        this.pack();
        this.setVisible(true);
    }

    public void focusGained(FocusEvent e)
    {
        if(e.getSource()==tf)
            {
                tf.setText("");
                tf.setForeground(Color.black);
            }

    }
    public void focusLost(FocusEvent e){}


    File f;
    FileInputStream fi;
    BufferedReader br;
    public void actionPerformed(ActionEvent e)
    {
        f=new File(tf.getText());
        fi=new FileInputStream(f);
        br=new BufferedReader(new InputStreamReader(fi));
        String strText=null;

        while((strText=br.readLine())!=null)
        {
            strText=strText+"\n";
        }

        ta.setText(strText);
    }


    public static void main(String[] args)
    {
        new File();
    }
}
  • 写回答

3条回答 默认 最新

  • warmcore 2017-06-03 08:42
    关注

    把你的类名改成FileFrame或者其它非File的类名,并修改构造函数名就好了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。