sinat_36930749 2016-12-11 07:27 采纳率: 80%
浏览 5794
已采纳

JAVA如何在窗体中输出

package keylogger;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

//创建窗口
public class readFile extends JFrame{

JPanel JPanel1;

JLabel reading;

public readFile(){

    this.setSize(300,200);  

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  

    this.setTitle("Keylogger!");  

    this.setVisible(true);

    JPanel1 = new JPanel();

    add(JPanel1);

    reading = new JLabel();//感觉应该在这里添加输入的内容,但是不知道怎么调用下面读取的内容

    JPanel1.add(reading);

}

//读取TXT文件
public static void readFileMessage(String fileName) {

    File file = new File(fileName);

    BufferedReader reader = null;

    try {

        System.out.println("按顺序读取文件的内容如下:");

        reader = new BufferedReader(new FileReader(file));


        String string = null;

        int line = 1;
        // 按行读取内容,直到读入null则表示读取文件结束
        while ((string = reader.readLine()) != null) {

            System.out.println("line " + line + ": " + string);

            line++;
        }

        reader.close();

    } 
            catch (IOException e) {

        e.printStackTrace();

    } finally {

        if (reader != null) {

            try {
                reader.close();

            } catch (IOException e1) {

            }
        }
    }
}

//输出结果
public static void main(String[] args) {

    String fileName = "D:/temp/test.txt";

    System.out.println("输出文件的内容:");

    readFile.readFileMessage(fileName);

            readFile r = new readFile();
}

}
这是一个读取TXT文件的程序,我想把读取的内容显示在窗体中,但是不知道该如何编写,
希望各位大神能给我一些帮助,感激不尽!!!

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号