首页 > 编程语言 > 详细

java 读取显示txt内容(Swing)

时间:2015-05-28 10:48:13      阅读:387      评论:0      收藏:0      [点我收藏+]

java 读取显示txt内容(Swing),JTextArea

public class TxtSwing extends JFrame {

    private JTextArea textAreaOutput;

    public TxtSwing() throws IOException {
        super("txt");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.FlowLayout());
        textAreaOutput = new JTextArea("111", 45, 80);
        textAreaOutput.setSelectedTextColor(Color.RED);
        textAreaOutput.setLineWrap(true); // 激活自动换行功能
        textAreaOutput.setWrapStyleWord(true); // 激活断行不断字功能
        BufferedReader reader = new BufferedReader(new FileReader(
                "test.txt"));
        String str = reader.readLine();
        String end = null;
        while ((str != null)) {
            end = end + str + "\n";
            str = reader.readLine();
        }
        textAreaOutput.setText(end);

        getContentPane().add(textAreaOutput);
        setSize(1024, 768);

    }

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        TxtSwing tm = new TxtSwing();
        tm.setVisible(true);
    }

}

 

java 读取显示txt内容(Swing)

原文:http://www.cnblogs.com/harry335/p/4535257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!