Thread: Vector create
View Single Post
  #2 (permalink)  
Old 11-19-2007, 09:35 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.awt.*; import java.io.*; import java.util.*; import javax.swing.*; public class FileToVector { private JScrollPane getContent() { Vector<String> vector = new Vector<String>(); JTextArea textArea = new JTextArea(); File file = new File("FileToVector.java"); Scanner scanner = null; try { scanner = new Scanner(file); } catch(FileNotFoundException e) { System.out.println("file not found: " + e.getMessage()); } while(scanner.hasNextLine()) { String line = scanner.nextLine(); vector.addElement(line); } scanner.close(); for(int j = 0; j < vector.size(); j++) textArea.append(vector.get(j) + "\n"); return new JScrollPane(textArea); } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new FileToVector().getContent()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
Reply With Quote