Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import java.awt.Dimension;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- import javax.swing.JTree;
- import javax.swing.SwingUtilities;
- public class FileToFrame extends JFrame {
- private static final long serialVersionUID = 1L;
- public FileToFrame() {
- initUI();
- }
- public final void initUI() {
- JPanel panel = new JPanel();
- JTextArea area = new JTextArea();
- //area.append("blablabl");
- area.setPreferredSize(new Dimension(100, 100));
- area.setEditable(false);
- area.setLineWrap(true);
- String line = null, test ="file.txt";
- FileReader citim = null;
- BufferedReader br = null;
- try {
- File file = new File(test);
- citim = new FileReader(file);
- br = new BufferedReader(citim);
- while((line = br.readLine()) != null) {
- area.append(line); // copy from file to JTextArea
- }
- } catch (Exception e) {
- System.out.println("Nu gasesc fisierul "+test);
- } finally {
- if(br != null) {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- panel.add(area);
- add(panel);
- pack();
- setTitle("FlowLayout Example");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocationRelativeTo(null);
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- FileToFrame ex = new FileToFrame();
- ex.setVisible(true);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement