import java.io.*;
import javax.swing.*;
public class Main{
public static void main(String[] args){
JFrame frame = new JFrame("JTextArea Application");
JTextArea textArea = new JTextArea();
String text = "";
try{
FileReader fr = new FileReader("D://data.txt");
BufferedReader reader = new BufferedReader(fr);
String textLine = "";
while(textLine!=null){
textLine = reader.readLine();
text = text + textLine + "\n";
}
}catch(Exception ex){
ex.printStackTrace();
}
textArea.setText(text);
frame.add(new JScrollPane(textArea));
frame.setSize(400, 300);
frame.setLocation(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
No comments:
Post a Comment