zoukankan      html  css  js  c++  java
  • java 读取显示txt内容(Swing)

    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 + "
    ";
                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);
        }
    
    }
  • 相关阅读:
    序列化注意事项
    HTML5的新结构标签
    MVC模型
    CSS选择器权重计算规则
    HTML常用布局
    盒模型
    Spring Security 学习笔记-session并发控制
    java实例之随机点名
    java之方法重载
    java之方法
  • 原文地址:https://www.cnblogs.com/harry335/p/4535257.html
Copyright © 2011-2022 走看看